a run function gives an error due to size

1 回表示 (過去 30 日間)
Berfin Çetinkaya
Berfin Çetinkaya 2022 年 4 月 2 日
コメント済み: Jan 2022 年 4 月 3 日
Hi
for bi= 1: 10;
bj= 1 : 10;
resultt(bi,bj) = birfazson(1,birfazson(2,:) == 1).'
end
I have such code in my file. When I run this it gives an error like this:
Unable to perform assignment because the size of the left side is 1-by-10 and the size of the right side is 5-by-1.
Error in pirellinew_02042022 (line 101)
resultt(bi,bj) = birfazson(1,birfazson(2,:) == 1).'
My right side values may change every time I run it. So what can I do in this situation?
  1 件のコメント
Jan
Jan 2022 年 4 月 2 日
It depends on what you want to achieve. You didn't mention this yet.

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

回答 (1 件)

Jan
Jan 2022 年 4 月 2 日
Maybe:
resultt = nan(10, 10);
for bi = 1:10
r = birfazson(1, birfazson(2,:) == 1);
if ~isempty(r)
resultt(bi, 1:numel(r)) = r;
end
end
The body of the loop doe not depend on the loop counter bi. I assume, this is a simplification for the question in the forum.
  2 件のコメント
Berfin Çetinkaya
Berfin Çetinkaya 2022 年 4 月 2 日
I wanted to find the sequences with 1 in the matrix named birfazson (in the first row) and print them one after the other in the first column of another matrix (resultt matrix).
Then I want to repeat this for values 2,3,4,5,6,7,8,9,10.
So as the second operation
I wanted to find the sequences with 2 in the matrix named birfazson (in the first row) and print them one after the other in the second column of another matrix(resultt matrix). And I intended to repeat that up to 10.
Jan
Jan 2022 年 4 月 3 日
What does this mean: "wanted to find the sequences with 1 in the matrix"?
Please give us some example data for the input and the wanted output.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by