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.

답변 (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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by