Indexing all the row data for each column
18 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
For example, if I had a matrix with 10 rows but variable column lengths for each row how would I iterate "for all row datapoints within each column"?
Right now using A(1:end,1:end) returns the entire matrix, but I would need to isolate each column of data.
Thank you in advance
3 个评论
Rik
2021-6-23
You can't have non-rectangular arrays in Matlab.
You can approximately get the same effect by using a cell array, or by padding with NaN. The most optimal strategy will depend on what you want to do.
回答(1 个)
millercommamatt
2021-6-23
For a 2D matrix, you can access a row as follows:
% Matlab indexing is row major
% return single row of matrix A
A(1,:)
A(2,:)
A(end,:)
%return single column of A
A(:,1)
A(:,2)
A(:,end)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!