how to exract varying matrix data
2 次查看(过去 30 天)
显示 更早的评论
I have a file X=(20,350) and i want to select the column value using a selecting a selcting matrix y= (1,350)
for i= 1:350
p(y(i),:)= X(1:y(i),:)
end
but couldn't solve the problem . any help in this regard is highly appreciated.
0 个评论
采纳的回答
Iain
2013-6-18
p(y(i),:)= X(1:y(i),:)
Is trying to put a y(i) by "n" matrix into a 1 by "n" matrix, which CANNOT work.
p(y(i),:)= X(y(i),:)
Is trying to put a 1 by "n" matrix into a 1 by "n" matrix, which can work, provided that "y" has enough elements.
If you define y to be a list of the ROWS you want (this is the way round you've got your code, swap the :, and y(i) round for columns):
p = zeros(size(X)); % or ones, or NaNs, or whatever else as needed.
y = [1 5 7 8 9 350];
for i = 1:numel(y)
p(y(i),:) = X(y(i),:);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!