How can I use tblwrite in Matlab
Show older comments
I have data which are as the following :
rownames11{kk}=char(rownames1(1,j))----1x225
colnames11={'K_minus_t';'K_minus_d';'a';'b';'c';'Err'}----1X6
values11{kk}}=[K_minus_t(j) K_minus_d(l) c resnorm]------1x225 ( variabe C contain three Values)
end
end
tblwrite(values11,colnames11,rownames11,'functionfitting.txt')
I tried to put these data as table type txt files by using tblwrite when I implement the code I receive this massage:
Error using tblwrite (line 64) Number of case names must equal number of data rows.
Error in lamm (line 96) tblwrite(values11,colnames11,rownames11,'functionfitting.txt');
Any help would be greatly appreciated. I will be grateful to you.
4 Comments
Geoff Hayes
on 18 Sep 2014
Ahmed - the error message Number of case names must equal number of data rows is telling you that there is a discrepancy between the number of elements in rownames11 and the number of rows in data. Just prior to calling tblwrite, type the following in the Command Window
size(values11)
size(colnames11)
size(rownames11)
What are the results for all three? If values11 is an mxn matrix, is rownames11 an mx1 (or 1xm) vector and is colnames11 an nx1 or(1xn) vector?
Geoff Hayes
on 18 Sep 2014
Ahmed - is the above code (in your question) correct, since it seems to imply that the number of rows is 225 and the number of columns is 6?
Regardless, try creating Values11 to a numeric matrix with 6 rows and 225 columns, rather than using a cell array
Values11 = zeros(6,225); % pre-allocate memory outside of for loops
for … %
% do stuff
rownames11{kk}=char(rownames1(1,j));
colnames11={'K_minus_t';'K_minus_d';'a';'b';'c';'Err'};
values11(:,kk)=[K_minus_t(j) K_minus_d(l) c resnorm]';
end
Note how the last line (in the above) sets the kkth column to a 6x1 vector (I added the apostrophe to transpose this to a column vector).
The you can call tblwrite but make sure that the second and third inputs are correct - since Values11 is 6x225, then the second input must have 225 strings, and the third input have six strings.
Ahmed
on 19 Sep 2014
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!