a run function gives an error due to size

1 view (last 30 days)
Berfin Çetinkaya
Berfin Çetinkaya on 2 Apr 2022
Commented: Jan on 3 Apr 2022
for bi= 1: 10;
bj= 1 : 10;
resultt(bi,bj) = birfazson(1,birfazson(2,:) == 1).'
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 Comment
Jan on 2 Apr 2022
It depends on what you want to achieve. You didn't mention this yet.

Sign in to comment.

Answers (1)

Jan on 2 Apr 2022
resultt = nan(10, 10);
for bi = 1:10
r = birfazson(1, birfazson(2,:) == 1);
if ~isempty(r)
resultt(bi, 1:numel(r)) = r;
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.
Jan on 3 Apr 2022
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.

Sign in to comment.


Find more on Operators and Elementary Operations in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!