Hallo :)
I am trying to conduct seven subplots with three graphs each. I have conducted one subplots but i have a hard time naming the codes inside the subplote correctly. Can you help me?

9 件のコメント

Mathieu NOE
Mathieu NOE 2022 年 3 月 24 日
hi Ditmer
inside the for loop you have to create a new figure at each loop iteration
so before the line "subplot(3,1,1)" insert a new line with :
figure(i);
Mathieu NOE
Mathieu NOE 2022 年 3 月 24 日
I suspect that you created one figure object at the very beginning of the code , but we cannot see it because i guess it's hidden by the "Run to Here" windows on top of the editor window
so this line should be removed / commented and remove also the "hold on" which is then no more needed
Ditmer Kiis
Ditmer Kiis 2022 年 3 月 24 日
Hey. Thanks for answering
No, just a "clc"
Ditmer Kiis
Ditmer Kiis 2022 年 3 月 24 日
Im in doubt how i should name the the variables time, vol, plot etc to get 7 figures.
Mathieu NOE
Mathieu NOE 2022 年 3 月 24 日
I would suggest that you do the data loading inside the for loop instead of writting seven fil variables at the beginning
also please do not use i or j as loop index as they are normally reserved for complex numbers (i² = -1 , j² = -1)
for k = 1:7
% load data
filename = ['s1_r' num2str(k) '.txt']; % file to be loaded
fil = ReadVerTxt(filename,3);
time = ...
vol = ...
% plot
figure(k)
subplot(311) .... % etc etc
end
Ditmer Kiis
Ditmer Kiis 2022 年 3 月 24 日
It dosent seems to help. I have made this graph for the first file in another script. i was hoping one could make a script so i could get 7 similar subplots
.
____
Now i have to re-do it 7 times but with-in a loop.
Sorry if i am completly retarded. I am new to Matlab.
Mathieu NOE
Mathieu NOE 2022 年 3 月 25 日
hi Ditmer
no one will blame you because you are new to Matlab (everybody was a novice too some day !)
I can further help you if you can share the data files (zip them) + your code (including the subfunctions for reading the text files)
Mathieu
Ditmer Kiis
Ditmer Kiis 2022 年 3 月 29 日
Hey Mathieu. Was in Paris a couple of days therefore im a litle late with the answer.
The files is in a zip folder.
Mathieu NOE
Mathieu NOE 2022 年 3 月 29 日
Hi Ditmer
hope you enjoyed your stay in Paris (that's where I work - to be more precise 70 kms south of Paris)
try this code :
clc
clearvars
for k = 1:7
% load data
filename = ['s1_r' num2str(k) '.txt']; % file to be loaded
fil = readmatrix(filename,"NumHeaderLines",7);
time = fil(:,1);
flowrate = fil(:,2);
vol = fil(:,3);
cumsum_flowrate = cumsum(flowrate);
time_step = time(2)-time(1);
vol_kontrol = -time_step * cumsum_flowrate;
figure(k)
subplot(3,1,1);
plot(time,vol,'LineWidth',3);
xlabel('time');
ylabel('vol');
subplot(3,1,2);
plot(time,flowrate,'LineWidth',3);
subplot(3,1,3)
plot(time,vol_kontrol,'LineWidth',3);
end

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

回答 (2 件)

Voss
Voss 2022 年 3 月 24 日

0 投票

files = sprintfc('s1_r%d.txt',1:7).';
for ii = 1:numel(files)
fil = ReadVerTxtData(files{ii},3);
time = fil(:,1);
flowrate = fil(:,2);
vol = fil(:,3);
% sum_flowrate = sum(flowrate);
cumsum_flowrate = cumsum(flowrate);
time_step = time(2)-time(1);
vol_kontrol = -time_step * cumsum_flowrate;
figure();
subplot(3,1,1);
plot(time,vol,'LineWidth',3);
xlabel('time');
ylabel('vol');
subplot(3,1,2);
plot(time,flowrate,'LineWidth',3);
subplot(3,1,3)
plot(time,vol_kontrol,'LineWidth',3);
end
Ditmer Kiis
Ditmer Kiis 2022 年 4 月 13 日

0 投票

Hey
I forgot to answer you.
Thank you very much for your time and patience! I am extremely grateful
Paris was great, superb weather (guess we were lucky), good food, vine etc..
Greetings!

1 件のコメント

Mathieu NOE
Mathieu NOE 2022 年 4 月 13 日
hello Ditmer
good news !
all the best

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

カテゴリ

質問済み:

2022 年 3 月 24 日

コメント済み:

2022 年 4 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by