Clear Filters
Clear Filters

copy datas, one above the others, in a new matrix

1 view (last 30 days)
Hi! I am a beginner in matlab.
I want to copy the first two columns of my variable cnt in a new variable called o : and my 3rd column = 1 :
[i,j] = size (cnt) ;
o(:,1:2) = cnt(:,1:2) ;
o(:,3) = 1 ;
Then I have new datas from cnt2, and I want to copy the first two columns UNDER the datas I have already copied from cnt : and my 3rd column = 2 for these news datas :
[h,k] = size (cnt2) ;
o(i:i+h,1:2) = cnt2(1:h,1:2) ;
o(i:i+h,3) = 2 ;
I have this error message:
Subscripted assignment dimension mismatch.
Can you help me? Thank you! Aude

Accepted Answer

the cyclist
the cyclist on 20 Nov 2016
In place of this ...
o(i:i+h,1:2) = cnt2(1:h,1:2) ;
o(i:i+h,3) = 2 ;
I think you intended this ...
o(i+1:i+h,1:2) = cnt2(1:h,1:2) ;
o(i+1:i+h,3) = 2 ;

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!