How can i perform the for loop in this case?

조회 수: 2 (최근 30일)
RADWAN A F ZEYADI
RADWAN A F ZEYADI 2021년 12월 4일
답변: Mathieu NOE 2021년 12월 6일
Hi ,
i try to perform for loop but doesnt work as well ,the idea is my data is 153*1 i have exracted it from 3d array because in my project the data must be column vector but ihave to run for loop along 71 trace in the horizontal axis so first 153*1 at first position the next iteration must be at the second an so on and must be mantain the same dimension until 71 i hope i was clear enough,any suggestons please.
  댓글 수: 7
Voss
Voss 2021년 12월 5일
@RADWAN A F ZEYADI: OK, I have the code. Please describe the problem you are facing, and refer to variables by name. Is d_obs the 3d array you mention?
RADWAN A F ZEYADI
RADWAN A F ZEYADI 2021년 12월 6일
@Benjamin yes d_obs is 3d array must be 153*1 and i have to perfurm for loop in along horizontal axis for 71 positions so 153*1 at 1st iteration and 2nd 153*1 in the 2nd position an so on d_obs(:,1,:) in this way but if you see in the input of the function Esmda_inv d_obs must be 153*1 so the forloop before the esmda_inv function

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

답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 12월 6일
hello
not sure to have 100% understood the question but maybe this answer it ?
I,believe it's simply about reshaping data - either with for loop or with reshape ...
%% dummy data
data = 1:1:1000; % data
buffer = 153; % nb of samples
%% solution 1
m = length(data);
data = data(:); % convert data to col vector
k = fix(m/buffer);
data = data(1:k*buffer); % we can only process multiple of "buffer" size data length.
for ci=1:k
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer-1,m);
out_data(:,ci) =data(start_index:stop_index);
end
%% solution 2
m = length(data);
data = data(:); % convert data to col vector
k = fix(m/buffer);
data = data(1:k*buffer); % we can only process multiple of "buffer" size data length.
out_data2 = reshape(data,buffer,[]);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by