Map a 2D matrix into 3D using loop for allotment along the 3rd dimension
Afficher commentaires plus anciens
I am not able to map a 2D matrix into a 3D, in which I want the particular columns of original 2D matrix to be selected and separated by using 3rd dimension (or in other words breaking a continous data into trials based on columns' selection). I used to get it before, but somehow, I am facing trouble while doing this- it throws an error of "Subscripted dimension error mismatch". But, if I do allotment along the 3rd dimension, size mismatch in other 2 dimensions should not create a problem, this is what I think.
I am now doubtful after getting the dimension mismatch error for it in matlab.
My code is somewhat like this:
% data is 2D matrix of size 7*1298779
for i=1:20
data_trialwise(:,:,i)=data(:,begin(i):end(i)); % begin and end both have 20 elements with values less than the number of columns in data
end
2 commentaires
Turlough Hughes
le 6 Déc 2019
I would wager that the way you have generated begin and end do not provide an equal number of indices between them on each iteration. Try subtract the two to see if this is the case. Otherwise can you attach the variables?
Réponse acceptée
Plus de réponses (1)
You could try this.
clear data_trialwise
for i=20:-1:1
data_trialwise(:,:,i)=data(:,begin(i):end(i)); % begin and end both have 20 elements with values less than the number of columns in data
end
1 commentaire
Ritz
le 7 Déc 2019
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!