a= [1;2;3;4;5;6;7;8;9;10];
b= [1;3;4;5;6;9];
There is a 10x1 matrix double called a and a 6x1 matrix double called b.
The error is that the value cannot be substituted because the left side size is 10x1 and the right side size is 6x1.
I want to combine a and b and make it a 10x2 matrix by giving the nan value to the empty space.
I don't know if I should use the conditional statement or if it's right to make a 10x2 zeros matrix in the first place, but I don't have a clue. How do we solve this?
matlab
Please refer to the code below.
a= [1;2;3;4;5;6;7;8;9;10];
b= [1;3;4;5;6;9];
c=zeros(10,2);
c(:,1)=a;
c(:,2)=ones(10,1).*nan;
for i=1:10
for j=1:6
if a(i,1)==b(j,1)
c(i,2)=b(j,1);
break;
end
end
end
© 2025 OneMinuteCode. All rights reserved.