Error in a for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I’m trying to run a loop through some measurement but I keep getting this error "Unable to perform assignment because the size of the left side is 3-by-1 and the size of the right side is 2-by-1." Does anyone know a way around this?
o = B(1:50,2);
for ind = 1:length(o)
a1(:,ind) = diff(o);
[c1(:,ind),d1(:,ind)] = find(a1(:,ind)>2^15);
[e1(:,ind),f1(:,ind)] = find(a1(:,ind)<-2^15);
o(c1(:,ind)+1:e1(:,ind)) = o(c1(:,ind)+1:e1(:,ind))-2^16; % Error Happens here
end
4 commentaires
dpb
le 14 Juil 2019
No idea what you're trying to explain, sorry.
Show us some data that illustrates what you're after with inputs and expected outputs and how you know those are the right answers given the input.
What is the end starting format and then the "the format I need" for the data? Bound to be a more effective way to code this if we just knew what the problem was/is...
Réponses (1)
SaiDileep Kola
le 17 Juil 2019
Hi,
I see that you get the error in 3rd line in the for loop not in the of 4rth line as you mentioned, I think your use case can be realized with the following code.
o = B(1:50,2);
for ind = 1:length(o)
a1 = diff(o);
c1 = find(a1>2^15);
e1 = find(a1<-2^15); %Error happens here
o(c1+1:e1) = o(c1+1:e1)-2^16; % Error doesn't occur here
End
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!