MATLAB cannot call or index into a temporary array in for loop

1 回表示 (過去 30 日間)
hello_world
hello_world 2016 年 5 月 17 日
コメント済み: Walter Roberson 2018 年 7 月 17 日
Hello Friends,
Here is my code:
M = {'a', 'b', 'c'};
for i = length(M)
M(i) = M(i)(M(i)~=0);
end
In other words, I am trying to get for each vector 'a', 'b', and 'c' the following in for loop:
a = a(a~=0);
b = b(b~=0);
c = c(c~=0);
I get the following error: "cannot call or index into a temporary array"
I will appreciate any advice.
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 17 日
Please do not close a Question that has an Answer.

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

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 17 日
I don't know what you want, your example is not appropriate, comparing letters with 0!
A=[1 2 0 5 0 7]
B=A(A~=0)
  1 件のコメント
hello_world
hello_world 2016 年 5 月 17 日
編集済み: hello_world 2016 年 5 月 17 日
I have a cell array, and I want to remove 0 entries from M. I want to do it for each 'a', 'b' and 'c' in for loop. In other words, it will be
a = a(a~=0);
b = b(b~=0);
c = c(c~=0);

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


Walter Roberson
Walter Roberson 2016 年 5 月 18 日

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by