필터 지우기
필터 지우기

For over three dimensional data

조회 수: 1 (최근 30일)
University Glasgow
University Glasgow 2023년 1월 4일
댓글: Rik 2023년 2월 1일
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
Rik
Rik 2023년 2월 1일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

MarKf
MarKf 2023년 1월 4일
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
MarKf
MarKf 2023년 1월 4일
편집: MarKf 2023년 1월 4일
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,:));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by