For a matrix with an unknown number of rows, how to find the number of rows n and transform it into n matrices.

8 次查看(过去 30 天)
  8 个评论

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-12-11
编辑:Ameer Hamza 2020-12-11
You can find the number of rows in a matrix using size()
data1;
n = size(data,1)
or height() [only in R2020b and later]
data1;
n = height(data)
The second part of your question about transforming it into a matrix is not clear.

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2020-12-11
编辑:Ameer Hamza 2020-12-11
I guess you are trying to do something like this
rows = data1(:,2);
cols = data1(:,1);
M = zeros(max(rows), max(cols));
idx = sub2ind(size(M), rows, cols);
M(idx) = 1;
Result
>> imshow(M)
  4 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by