Can using cell arrays produce unexpected matrix dimension errors?

1 view (last 30 days)
I'm attempting to write default data values to a text file using the following code;
Default_Cam_Data = {
'Cam ID:' 1 ;
'pad 6:' -1 ;
'SW ID:' 1 ;
'Position:' 0.0000000, 0.0000000, 0.0000000 ;
'Range:' 0.0 ;
'Cam Status:' -1 ;
'Tolerance Count:' 0 };
[nrows,ncols]= size(Default_Cam_Data);
filename = 'camera_data.txt';
fid = fopen(filename, 'w');
Total_Cams_Reporting = 3;
for m = 1:Total_Cams_Reporting
fprintf(fid, 'Observing Cameras Info (%d of %d)\n', m, Total_Cams_Reporting);
for row=1:nrows
fprintf(fid, '%s %d\n', Default_Cam_Data{row,:});
end
end
fclose(fid);
When I open the text file, I expect the data to be written like this;
Observing Cameras Info (1 of 3)
Cam ID: 1
pad 6: -1
SW ID: 1
Position: 0.0000000, 0.0000000, 0.0000000
Range: 0
Cam Status: -1
Tolerance Count: 0
Observing Cameras Info (2 of 3)
Cam ID: 1
pad 6: -1
SW ID: 1
Position: 0.0000000, 0.0000000, 0.0000000
Range: 0
Cam Status: -1
Tolerance Count: 0
Observing Cameras Info (3 of 3)
Cam ID: 1
pad 6: -1
SW ID: 1
Position: 0.0000000, 0.0000000, 0.0000000
Range: 0
Cam Status: -1
Tolerance Count: 0
However, I keep getting the following error:
Warning: File: Cam.m Line: 2 Column: 20
The expression on this line will generate an error when executed. The error will be: Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error using Cam (line 1) Error using vertcat Dimensions of matrices being concatenated are not consistent.
I suspect the problem has something to do with the 3 default values for position since I can delete the last 2 occurences of 0.0000000, and I get this result: Position: 0
This is the first time I've seen this. Any ideas on what could be the source of this error?
  2 Comments
Matt J
Matt J on 7 Jan 2014
Edited: Matt J on 7 Jan 2014
Warning: File: Cam.m Line: 29 Column: 20 ... Error using vertcat
Could you show us the code up through Line 29, in accordance with the warning? The code you've shown only has 21 lines. Furthermore, none of the lines you've shown contain a vertcat() operation.
Brad
Brad on 7 Jan 2014
Matt, I just noticed this as well. I updated the original information to reflect the same result after I deleted all the comments proceeding the code.
The vertcat error has me completely confused. I'm not invoking that function anywhere in the code, but I'm getting an error?

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 7 Jan 2014
Edited: Sean de Wolski on 7 Jan 2014
Hey Brad,
vertcat() is what is called when you use a ";" to vertically concatenate an array, e.g.:
x = [1; 3]
is equivalent to
x = vertcat(1,3)
What's happening with your file above is you have a bunch of 1x2 rows and then you try to concatenate them vertically with a 1x4 row.
'Cam ID:' 1 ;
'pad 6:' -1 ;
'SW ID:' 1 ;
'Position:' 0.0000000, 0.0000000, 0.0000000 ; % This guy has four elements
You'll need to either make the whole cell array an nx4 or figure out how to reduce those three 0.00000s to one, possible using a nested cell {0.00 0.00 0.00}
  2 Comments
Sean de Wolski
Sean de Wolski on 7 Jan 2014
Ps. good well written question that should be an example for others! You gave us the full code, indented as code and the full warning!
Brad
Brad on 7 Jan 2014
Thanks Sean. I've botched a few questions pretty good over the last year.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!