Editing cell array values (each cell is a matrix)

조회 수: 2 (최근 30일)
Ahsan  Khan
Ahsan  Khan 2018년 5월 10일
댓글: Ameer Hamza 2018년 5월 12일
M=[];
M=dlmread('data.txt', '\t');
dataArray=M;
C= corrcoef(M(:,1:end));
imagesc(C);
cb = colorbar;
ylabel(cb, 'Correlation Coefficient');
moo=sqrt(C^.2)
moos=[]
for l=0:.1:1;
moo(moo<l)=0;
moos{end+1} = moo;
moos(moos>0)=1;
The last opertaion fails since > is an undefined operator for input arguments like cell. I unsuccessfully tried to make a function for the last line and implement it in cellfun. What would be the proper syntax here?
  댓글 수: 2
Stephen23
Stephen23 2018년 5월 11일
편집: Stephen23 2018년 5월 11일
@Ahsan Khan: what is your question?
Ahsan  Khan
Ahsan  Khan 2018년 5월 11일
편집: Ahsan  Khan 2018년 5월 11일
Well I figured out what I needed but now I'm trying to work out my next step, updated the question

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

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 12일
"The last operation fails since > is an undefined operator for input arguments like the cell."
You cannot directly perform the comparison on cell array. you need to access its element using curly brackets and then operate on them. For example, the following syntax will work
moos{end}(moos{end}>0) = 1;
to apply this operation to all elements of moos use cellfun as following
moos = cellfun(@(x) x.*(x<0)+(x>0)*1, moos, 'UniformOutput', 0)
  댓글 수: 2
Ahsan  Khan
Ahsan  Khan 2018년 5월 12일
I see, I saw the second format on another forum page, can you explain the @(x) x.*(x<0)+(x>0)*1 piece. For all entries if x<0 or x>0 set equal to 0?
Ameer Hamza
Ameer Hamza 2018년 5월 12일
x.*(x<0)+(x>0)*1 means that if entries are less than 0 than don't change them but if they are greater then 0, then make them 1. This is what I thought you are trying to do from your line
moos(moos>0)=1;

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

추가 답변 (1개)

possibility
possibility 2018년 5월 11일
before starting the iteration,
mos=[];
"before starting the removal of the next mo", most probably inside-end of the iteration,
mos{l*10}=mo;
  댓글 수: 1
Ahsan  Khan
Ahsan  Khan 2018년 5월 11일
편집: Ahsan  Khan 2018년 5월 11일
This adds the entry only to the last space of mos{} All other entries are empty,
Update: Got it working with the following code.
moos=[]
...
for l=0:.1:1;
moo(moo<l)=0;
moos{end+1} = moo;
end;
...

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

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by