Variable name in title

After loading in a data file, the following variables are assigned to the individual columns of the data file:
pressure1=dataFile(:,1);
temperature1=dataFile(:,2);
humidity1=dataFile(:,3);
...
If I plot all the columns using a for loop,
for i=1:47
figure;
Plot(dataFile(:,i))
title
saveas
close
end
then what to write in the title line so that it automatically puts 'pressure1' as the title when i=1, 'temperature1' as the title when i=2, 'humidity1' as the title when i=3, and so on? Also, how to use the saveas command (or any other alternative) so that the figure gets saved in the variable names, i.e. pressure1.jpg, temperature1.jpg, humidity1.jpg etc.

回答 (2 件)

Jan
Jan 2017 年 3 月 31 日

1 投票

Althoug meaningful names of variables are a good programming practice, they should not carry information which is used for processing. The output of a program should be the same, if a variable is renamed. Then:
NameList = {'pressure1', 'temperature1', 'humidity1', ...}
for i=1:47
figure;
plot(dataFile(:, i))
title(NameList{i})
end

3 件のコメント

b
b 2017 年 3 月 31 日
How can the NameList be extracted from the already declared variables? All the columns of the data file have already been assigned the variable names.
gowtham balu
gowtham balu 2021 年 11 月 28 日
how do i use loops to find the min and max value within a specified range of values.
every 0.5 seconds there is a sample taken. 0 to 0.5s one max and min value ...so 0.5s= 1 cycle. totally 10000 cycles.
please see the attached text file with this comment
please help me....because i dont know how to use syntax in matlab
Steven Lord
Steven Lord 2021 年 11 月 28 日
This does not appear to be related to the original question. Ask it as a new question instead of as a comment on an answer for this existing question.

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

KSSV
KSSV 2017 年 3 月 31 日

0 投票

for i=1:47
figure;
Plot(dataFile(:,i))
str = strcat('pressure',num2str(i)) ;
title(str)
saveas(gcf,str,'jpg')
close
end

1 件のコメント

b
b 2017 年 3 月 31 日
No.

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

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

質問済み:

b
b
2017 年 3 月 31 日

コメント済み:

2021 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by