Hello everyone.
I have a plot generated by Matlab to which I want to add a box containing some error metrics I produced by my own (please see attached).
These statistics are *not* the ones from Tools -> Data statistics. Is there a way to achieve that?
Thanks in advance!

 採用された回答

Rik
Rik 2020 年 2 月 13 日
編集済み: Rik 2020 年 2 月 13 日

0 投票

You can add information to a plot with an annotation, or you can use the rectangle and text functions. The code below will read your data and adapt the example in the documentation.
file='Daily_Stats_Automn2015 Airport Temperature .csv';
%read the whole file, split at the newline, then split at the comma
headers=fileread(file);
headers=split(headers,newline);
headers=split(headers{1},',');
%read the data
data=readmatrix(file,'NumHeaderLines',1);
%format data and text to a cell array
txt=cell(numel(headers),1);
for n=1:numel(txt)
txt{n}=sprintf('%s = %.4f',headers{n},data(n));
end
figure(1),clf(1)
plot(0:10,0:10)
x = [0.35 0.5];
y = [0.6 0.5];
annotation('textarrow',x,y,'String',txt);

5 件のコメント

Daphne PARLIARI
Daphne PARLIARI 2020 年 2 月 13 日
No, I don't know how to read data to a variable... :-/
Could you please explain that?
Rik
Rik 2020 年 2 月 13 日
This is fairly basic Matlab, so you should consider doing a Matlab tutorial. See my edited answer for an example.
Daphne PARLIARI
Daphne PARLIARI 2020 年 2 月 26 日
I finally tried t replicate your suggestion, thank you very much!
Is there a way to choose just some of the metrics contained in the .csv to insert to the graph, instead of the entire file?
I tried several paths but none of them gave the result I need.
Rik
Rik 2020 年 2 月 26 日
If you know the order in which the parameters appear you can select them by modifying the for loop.
Daphne PARLIARI
Daphne PARLIARI 2020 年 2 月 27 日
Dear Rik, thank you for you time!
Could I ask one more thing, the answer to it I wasn't able to find in MathWorks?
The plot I want is generated well enough so far using the following lines:
%read the whole file, split at the newline, then split at the comma
headers=fileread(Calc_Stats_file);
headers=split(headers,newline);
headers=split(headers{1},',');
%read the data
data=readmatrix(Calc_Stats_file,'NumHeaderLines',1);
%format data and text to a cell array
txt=cell(numel(headers),1);
for n=1:numel(txt)-10
txt{n}=sprintf('%s = %.4f',headers{n},data(n));
end
annotation('textarrow','String',txt);
hold on;
outfile_fig=[output_path,'\',stations{i},'\','\TSHourly_OBSvsWRF.tif'];
plot_ts(All_Data.Hourly_Temp_mean(:),All_Data.Temp(:),thour(1),'hours',[vars{1},' (',varunits{1},')'],'WRF', 'Obs.',[vars{1},' timeseries for ',stations{i},' station'],outfile_fig);
hold off;
The problem is that the graph in the pop-up window disappears after 1 sec., therefore I cannot make the changes I want. Probably it's something with hold on/off I guess, but what do I do wrong?
Thank you once again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by