I want to export matlab output to an excel file starting from G2 column and for this the code i had written is exporting the data correctly but not to the desired location .It is printing in 21st number of rows rather than 2nd.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
himakshi Shekhawat
am 13 Jan. 2015
Kommentiert: Geoff Hayes
am 13 Jan. 2015
the code is
ResultFile = xlsread('filename');
sz= size(ResultFile,1);
b= num2str(sz+1);
location = strcat('G2',b);
fprintf('value in location is %g\n',location);
xlswrite('filename',fnlarray,'Sheet1',location);
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 13 Jan. 2015
Himakshi - what is sz? From your code, it appears to be the number of rows in the data ResultFile. You then create a variable b from sz as
b= num2str(sz+1);
and then concatenate this to G2 as
location = strcat('G2',b);
So if sz is zero, the b is one, and so location is G21 which may explain the behaviour that you are observing.
The result of the fprintf should tell you which row of column G that you are are writing the data to. What does this line of code write to the command window? What are the dimensions of ResultFile and why, if you want to write the data to the second row of column G, are you creating this location variable?
If all you want to do is write the data at G2, then your code should simply be
xlswrite('filename',fnlarray,'Sheet1','G2');
In the above, presumably 'filename' is just a placeholder for the name of the file, and you are not referencing a local variable called filename (as this would be incorrect usage of this string).
2 Kommentare
Geoff Hayes
am 13 Jan. 2015
Change your fprintf so that you are printing a string on each iteration of the loop. Try
fprintf('value in location is %s\n',location);
What is the output now? And since you are iterating over the above code, where do you want the other data (on say the second iteration) to go i.e.which column which row, etc.?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!