To get the number of columns in an array in MATLAB, you can use the size function and specify the second output as the number of columns. Here's the code:
main.m179 chars9 lines
In this example, the array has 3 columns, so the output will be:
main.m2 chars2 lines
Note that the size function returns a matrix, where the first element represents the number of rows and the second element represents the number of columns. By specifying the second output 2, we are extracting only the number of columns.
gistlibby LogSnag