MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Using Arrayfun for iterative plotting

Manuel Arcangeletti さんによって質問されました 2019 年 5 月 15 日
最新アクティビティ Manuel Arcangeletti さんによって コメントされました 2019 年 5 月 16 日
Hi all,
I'm trying to plot all the elements of a cell array using the command arrayfun instead of a for loop.
My cell array is the following:
It gives me error when I use this sintax:
arrayfun(@(x)plot(repmat(x{6,2:end},1,x{2,2:end}),x{7,2:end},Gen_Array))
Can anybody please help me with this?
Thank you very much,
Manuel

  4 件のコメント

Jan
2019 年 5 月 15 日
@Manuel: Why do you prefer arrayfun instead of a clean loop? It will not be faster, but harder to create the code, as you see.
Manuel Arcangeletti 2019 年 5 月 16 日
James and Jan, thank you for your reply!
All I would like to do is have a really easy method to plot different things contained into my array.
For example, now I would like to have separate boxplots with,
in the first plot:
the first row af all the columns of my Gen_Array (name of my array){7,2} ,Gen_Array{7,3}, ..., Gen_Array{7,end}.
in the second plot:
the second row af all the columns of my Gen_Array (name of my array){7,2} ,Gen_Array{7,3}, ..., Gen_Array{7,end}.
and so on...
I don't know if it is possible with an arrayfun... I only tought it was the easiest way...
Thank you very much!
Manuel
Jan
2019 年 5 月 16 日
A loop is easier to write and to debug.

サインイン to comment.

1 件の回答

Jan
回答者: Jan
2019 年 5 月 16 日
編集済み: Jan
2019 年 5 月 16 日
 採用された回答

For example:
for iRow = 1:2
plot(Gen_Array{7,2}(:, iRow), Gen_Array{7,3}(:, iRow));
end
I do not understand completely, what you want to plot:
"the first row af all the columns of my Gen_Array (name of my array){7,2} ,Gen_Array{7,3}, ..., Gen_Array{7,end}" - These are too many inputs for a plot() command, but maybe you can adjust me code to your needs.
arrayfun is an extremely compact method to avoid loops in the code. Internally the data are processed in loops also, so there is no real benefit for the execution. Use loops to follow the KISS concept: Keep it simple stupid.

  1 件のコメント

Manuel Arcangeletti 2019 年 5 月 16 日
Thank you very much Jan!!

サインイン to comment.



Translated by