What is wrong with this code?

조회 수: 2 (최근 30일)
Holmbrero
Holmbrero 2021년 1월 20일
댓글: Holmbrero 2021년 1월 21일
Why is this code not exchanging all negative numbers in Raddidifference and Truedist to NaN? Size1 is just the size of the cell array.
And also, can it be done without looping?
for n=1:Size1(2)
for k=1:Size1(1)
for i=length(Radiidifference{k,n})
R{k,n}=Radiidifference{k,n}
if R{k,n}(i,1)<0
Radiidifference{k,n}(i,1) = NaN
Truedist{k,n}(i,1:2) = NaN
end
end
end
end
Any help would be greatly appriciated!

답변 (1개)

Bob Thompson
Bob Thompson 2021년 1월 20일
I would think you could do this with cellfun and some logic, but I could be wrong.
cellfun(@(s) s((1:end)<0,1) = NaN,Radiidifference);
cellfun(@(s) s(Radiidifference{s}==NaN)=NaN,Truedist);
I haven't tested this, and I'm specifically not sure about the second portion, but the concept should be sound.
It technically still loops, that's what cellfun does, but it does clean things up a bit.
  댓글 수: 1
Holmbrero
Holmbrero 2021년 1월 21일
Thank you!
I'll give it a go.
/Anders

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by