How to import text present in figure to excel?
Ältere Kommentare anzeigen
Hello,
I wrote text in figure.For example:
figure
axis off
text(0,0.5,sprintf([ 'speed = %0.1f kmph (%0.1f miles/hour)\n'
'time = %0.1f min \n '
],speed,time;
And the output:
speed= 55kmph(30miles/hour)
time= 35min
How want import this output to excel?
Thank you in advance
2 Kommentare
Rik
am 28 Jan. 2022
Do you want to export the text as text? Or the figure as an image?
yojitha etikala
am 28 Jan. 2022
Antworten (1)
There is one way to write the output to *.xlsx-File.
speed= 55;
time= 35;
filename = 'Test.xlsx';
str = sprintf(['speed = %0.3f kmph \n' 'time = %0.1f min \n '],speed,time);
text(0,0.5,str);
OutPut = cellstr(str);
writetable(cell2table(OutPut),filename);
12 Kommentare
yojitha etikala
am 28 Jan. 2022
yojitha etikala
am 28 Jan. 2022
yojitha etikala
am 28 Jan. 2022
hi for me it is working fine. I didn't use writematrix before.Did you got this from File Exchange?
For writing to xls-File I prefer writetable command. see below result I am getting as per above solution.

can you post the code that you are using and also the error ?
Rik
am 31 Jan. 2022
yojitha etikala
am 1 Feb. 2022
Ankit
am 2 Feb. 2022
Above code you posted definitely throws an error if you str is not in table format.
When you are writing to xlsx using writetable the str has to be in table format thats why i used cell2table(str)
cellstr i used to convert into cell. Could you please tell me what is the type (cell, char etc) of your str?
yojitha etikala
am 2 Feb. 2022
Ankit
am 3 Feb. 2022
Your code will make str to return text object
str=text(0,0.5,sprintf([ ...
'Distance = %0.1f km (%0.1f miles)\n' ...
'Driving time = %0.1f min \n ' ...
'Avg speed = %0.1f kmph (%0.1f mph)\n ' ...
],DistanceTraveled,DistanceTraveled/1.609, Driving_time,Average_speed),'FontSize',14)
DistanceTraveled = 1;
Average_speed = 1;
Driving_time = 1;
filename = 'Test.xlsx';
str = sprintf([ ...
'Distance = %0.1f km (%0.1f miles)\n' ...
'Driving time = %0.1f min \n ' ...
'Avg speed = %0.1f kmph (%0.1f mph)\n' ...
],DistanceTraveled,DistanceTraveled/1.609, Driving_time,Average_speed);
text(0,0.5,str,'FontSize',10);
OutPut = cellstr(str);
writetable(cell2table(OutPut),filename);
Rik
am 3 Feb. 2022
If the goal is to write something to an excel file, why is the text function used at all? That is an unnecessary step that still confuses me.
Ankit
am 3 Feb. 2022
Yes one can avoid that step but it is not clear how he is getting the data. I just used the def values.. whether he is displaying that data in figure etc.. if not then text command is not required..
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
