Azzera filtri
Azzera filtri

For over three dimensional data

1 visualizzazione (ultimi 30 giorni)
University Glasgow
University Glasgow il 4 Gen 2023
Commentato: Rik il 1 Feb 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 Commento
Rik
Rik il 1 Feb 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.

Accedi per commentare.

Risposte (1)

MarKf
MarKf il 4 Gen 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 Commento
MarKf
MarKf il 4 Gen 2023
Modificato: MarKf il 4 Gen 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,:));

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by