how to assign value to a specific position in cell

조회 수: 21(최근 30일)
SM 2020년 7월 13일
댓글: Walter Roberson 2020년 7월 17일
B= [1,1,0,1;0,1,1,1;1,0,1,1;0,1,1,0];
for i=1:numel(a)
A{a(i),b(i)}=[100 100 100 100];
Is there any other ways instead of using for loop?

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 13일
if size(B,1) > size(A,1)
A(size(B,1),1) = {}; %extend A if needed
if size(B,2) > size(A,2)
A(1,size(B,2)) = {}; %extend A if needed
A(~B) = {[100 100 100 100]}; %replaces the find and the loop
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 7월 17일
You might be able to hide loops behind some cellfun() or arrayfun(), and abusing subsasgn() to do assignments using function call syntax...but otherwise, NO.

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by