Plotting based on a for loop from a cell array

3 ビュー (過去 30 日間)
Inti Vanmechelen
Inti Vanmechelen 2019 年 3 月 18 日
コメント済み: Inti Vanmechelen 2019 年 3 月 18 日
Hi every one,
I am trying to plot acceleration data, which I always have in X, Y & Z direction.
To avoid doing everything 3 times, I have created a cell array: names = {'X', 'Y', 'Z'}.
I now want to plot this data in 3 subplots using a for loop, which yields something like this:
for i = 1:length(names)
figure();
subplot(3,1,i);
plot(UA_SEG.Acc_(names{i}));
end
In which UA_SEG is a table containing the data I'm using.
However, I am doing something wrong in accessing the cell array, as it won't plot and I get the error "Error using tabular/dotParenReference (line 69), Unrecognized variable name 'Acc_'."
Which means that it does not recognize the first element of the array as being 'X', but I am not sure which braces or indexing to use to make this work.
Thank you in advance
Inti

採用された回答

Stephen23
Stephen23 2019 年 3 月 18 日
編集済み: Stephen23 2019 年 3 月 18 日
xyz = 'XYZ';
figure()
for k = 1:3
subplot(3,1,k)
plot(UA_SEG{:,['Acc',xyz(k)]})
end
  1 件のコメント
Inti Vanmechelen
Inti Vanmechelen 2019 年 3 月 18 日
Thank you Stephen!
I had looked at a lot of information pages before, but I hadn't found that one yet.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by