Index exceeds matrix dimensions error.
2 次查看(过去 30 天)
显示 更早的评论
Hi, I would like to know how to change the 0's in C that are in the same position where d1 finds values where (d<=d0) with the corresponding d2 value. d is a 100x1 array and d0 is the mean value. For instance if the first and fourth elements in d are less than d0, then the first and fourth elements in d2 are stored as the first and fourth elements in C respectively.
C=zeros(100,1);
d = randi(10, 100, 1);
d0 = mean(d);
d1=find(d<=d0);
d2 = randi(10, length(d1), 1);
C(d1)=d2(d1);
0 个评论
采纳的回答
Adam
2015-4-21
You should just be able to replace that last line with
C(d1)=d2;
You have already trimmed d2 to the size of d1 in the previous line.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!