Borrar filtros
Borrar filtros

For over three dimensional data

1 visualización (últimos 30 días)
University Glasgow
University Glasgow el 4 de En. de 2023
Comentada: Rik el 1 de Feb. de 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 comentario
Rik
Rik el 1 de Feb. de 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.

Iniciar sesión para comentar.

Respuestas (1)

MarKf
MarKf el 4 de En. de 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 comentario
MarKf
MarKf el 4 de En. de 2023
Editada: MarKf el 4 de En. de 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,:));

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by