How to make a new matrix from find function results of different size

1 回表示 (過去 30 日間)
Georgios Tertikas
Georgios Tertikas 2018 年 6 月 22 日
コメント済み: Ameer Hamza 2018 年 6 月 24 日
I have a matrix of IC 2008x1 that has values from 1 to 16 (some in between number might be missing) and I want to create a matrix that each column has the rows of the original matrix that correspond to each value 1 to 16 eg original matrix 4; 1; 3; 2; 5; 6; 4; new matrix [2] [4] [3] [1;7] [5] [6]
I try to do this like this for j=1:B
k=find(IC==j);
F(:,j)=k;
end where B is 16 but it says that Subscripted assignment dimension mismatch. Do you know an alternative that works regaldless of this mismatch?

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 6 月 22 日
In a normal array, all rows and columns must have equal length. You need to use a cell array
for j=1:B
k=find(IC==j);
F{j}=k;
end
  7 件のコメント
Georgios Tertikas
Georgios Tertikas 2018 年 6 月 24 日
now its says undefined variable or function newline
Ameer Hamza
Ameer Hamza 2018 年 6 月 24 日
You must be using R2016a or earlier. It that case, change the line like this
printf(f, [repmat('%f ', 1, numel(F{i})), 10], F{i});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by