Plot values ​​for different time steps in table

Hi,
I have a table with dimensions for 1:1048576 and I want to plot columns 2 and 3 for different time steps. The values ​​in the table are sorted in such a way that the next time step comes after 10498 rows. Can someone help me and tell me how to use a loop to automatically plot the different time steps? Instead of plotting 1:10498, 10499:20998, .....
Thank you and have a nice day

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 4 日

0 投票

perstep = 10498;
col2 = YourTable{:,2};
col3 = YourTable{:,3};
L = numel(col2);
full_steps = floor(L / perstep);
left_over = L - full_steps * perstep;
if left_over ~= 0
padding_size = perstep - left_over;
padding = nan(padding_size, 1);
col2 = [col2; padding];
col3 = [col3; padding];
end
col2 = reshape(col2, perstep, []);
col3 = reshape(col3, perstep, []);
It is not clear what you want on your x axes or y axes.
At the end of the code posted above, col2 and col3 are each 2D arrays, with as many rows as perstep (10498), and as many columns as needed to complete the signal (in particular, 100 columns). The final column in each of the two is padded with nan to complete the 10498 samples.
What to do next depends on what you want plotted. You could now, for example,
plot(col2)
and the result would be a plot with 100 lines, one per timestep.

3 件のコメント

Frederik Reese
Frederik Reese 2022 年 5 月 4 日
Thanks for your fast answer. to clearify:
I have a dike line (distance) and water levels on the dike. I have a table with dimensions for 1:1048576 and I want to plot columns 2 (distance) and 3 (water level) for different time steps. The values ​​in the table are sorted so that 10498 rows correspond to the same time step. So I like to plot lines 1 to 10498, then lines 10499 to 10499+10499,.... to 1048576. So that I don't have to do it by hand, I'm looking for a loop that does it for me. Hopefully it's clearer now. I'll try your suggestion. Thank you and have a nice day
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
編集済み: Walter Roberson 2022 年 5 月 4 日
If you wanted column 2 versus column 3, for each time step, then after the above,
for STEP = 1 : size(col2,2)
plot(col2(:,STEP), col3(:,STEP), 'DisplayName', "STEP = " + STEP);
hold on
end
hold off
legend show
Frederik Reese
Frederik Reese 2022 年 5 月 4 日
Thanks it works well.

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

カテゴリ

質問済み:

2022 年 5 月 4 日

コメント済み:

2022 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by