Effacer les filtres
Effacer les filtres

For over three dimensional data

1 vue (au cours des 30 derniers jours)
University Glasgow
University Glasgow le 4 Jan 2023
Commenté : Rik le 1 Fév 2023
I have a data of the form: A = 7x9x7, where u = [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6]. Please how can loop over u. I tried
for j = 1:length(u)
B(j) = squeeze(A(j,1,:));
end
such that I have: B(1) = squeeze(A(1,1,:)), B(2) = squeeze(A(2,1,:)), B(3) = squeeze(A(3,1,:)) ... until B(7) = squeeze(A(7,1,:))
but i received an error: Index in position 1 is invalid. Array indices must be positive integers or logical values.
  1 commentaire
Rik
Rik le 1 Fév 2023
I recovered the removed content from the Bing cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.

Connectez-vous pour commenter.

Réponses (1)

MarKf
MarKf le 4 Jan 2023
How is my whole Uni requesting help like this? Surely there are some people who could help within already...
Anyway, you should specify B(j,:) = squeeze(); maybe also preallocalocate before the loop B=nan(7,7) or nan(size(A,[1,3])) so you know what you are getting.
  1 commentaire
MarKf
MarKf le 4 Jan 2023
Modifié(e) : MarKf le 4 Jan 2023
Actually now that I think about it, that's not the error you would be getting in that case (it'd be something about indices and left/right sides)
A = ones([7,9,7]); u = [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6];
for j = 1:length(u)
B(j,:) = squeeze(A(j,1,:));
end
So maybe you did something else, like writing for j = u instead.
Besides, there is no need for a loop if you just need B = squeeze(A(:,1,:));

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by