Saving a 3D matrix in through FOR LOOP and plot this matrix with error bar with error bar

How can I save the each value for row,col and slice for the following output R, which will be a 3D matrix. Lastly, plot this 3D matrix with error bar.
Your kind help will be appreciated.
Thank you.
For example,
row = [0.3 0.4 0.5];
col = [0.3 0.4 0.5];
sl = [1 2]; % slice in z axis
output >> R : 3x3x2 MATRIX
for a = 1:numel(sl);
for b = 1:numel(col);
for C = 1:numel(row);
R = myfunction (some parameters)
end
end
end

回答 (1 件)

dpb
dpb 2022 年 9 月 20 日
R=zeros(numel(row),numel(col),numel(sl)); % preallocate
...
R(C,b,a)=myfunction(...);
...
is the brute force way using explicit loops. "The MATLAB way" would be to vectorize the function itselt such that it accepted the inputs as vectors/arrays of the proper sizes and hid the looping constructs from the higher-level code.
As for how to plot a 3D array with error bars -- that's going to be a pretty difficult thing to do -- without any idea what the 3D array content represents, tough to have much idea on what a plot would be expected to look like, even...

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2022 年 9 月 20 日

回答済み:

dpb
2022 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by