1

I have 100 column xlsx file with size (4097,100). I need to read first column and do some processing and this results in four row variables (1,4097 each) for the first column data only. Further, I need to process each of these four row variables to obtain its statistical parameters such as min, max, mean, SD, var in MATLAB. How to do it with nested for loop? I appreciate your help. The sample MATLAB code that I am trying is where I have considered only two columns A1 and A2:

A = xlsread('S.xlsx');
num_rows = size(A,1);
num_cols = size(A,2);
A1 = A (:,1);
A2 = A (:,2);
B = {A1,A2};
for i = 1:2
for j = 1:4
IMF = emd(B{i},'STOP',[0.1,0.5,0.05],'MAXITERATIONS',100);
I1 = IMF (1,:);
I2 = IMF (2,:);
I3 = IMF  (3,:);
I4 = IMF (4,:);
imf = {I1, I2, I3, I4};
m1(j) = mean(imf{j});
m2(j) = min(imf{j});
m3(j) = max(imf{j});
m4(j) = std(imf{j});
m5(j) = var(imf{j});
end
end

Another variation in the code I tried is:

A = xlsread('S.xlsx');
num_rows = size(A,1);
num_cols = size(A,2);
A1 = A (:,1);
A2 = A (:,2);
B = {A1,A2};
for i = 1:2
IMF = emd(B{i},'STOP',[0.1,0.5,0.05],'MAXITERATIONS',100);
I1 = IMF (1,:);
I2 = IMF (2,:);
I3 = IMF  (3,:);
I4 = IMF (4,:);
imf = {I1, I2, I3, I4};
for j = 1:4
m1(j) = mean(imf{j});
m2(j) = min(imf{j});
m3(j) = max(imf{j});
m4(j) = std(imf{j});
m5(j) = var(imf{j});
end
end

But no success. I am getting the stats values only for the first column i.e. four values for I1, I2, I3 and I4. The second column A2 is not being processed.

4
  • I need to read first column and do some processing and this results in four row variables (1,4097 each) for the first column data only what is the meaning of four row variables in this line? Commented Feb 26, 2017 at 11:36
  • Dear Muhammad, the processing of first column results in four separate variables, each with one row and 4097 columns. Sorry for confusion. I am close to the final answer, as suggested by m7913d, there is a problem of overwriting. This is solved. But now I need to work on making the code faster. Thank you for your help. Commented Feb 26, 2017 at 15:47
  • Please mark an answer as correct if it solved your problem or write an answer yourself, which may be useful for other people. Commented Apr 10, 2017 at 9:33
  • Why are you posting questions, receive answers and then delete the questions? Commented Jul 1, 2017 at 6:08

1 Answer 1

1

I think the problem is that you overwrite your results. You can always run your code step by step using the Matlab debugger to check what exactly happens.

A = xlsread('S.xlsx');
m1 = zeros(2, 4);
m2 = zeros(2, 4);
m3 = zeros(2, 4);
m4 = zeros(2, 4);
m5 = zeros(2, 4);
for i = 1:2
    IMF = emd(A(:, 1),'STOP',[0.1,0.5,0.05],'MAXITERATIONS',100);
    m1(i, :) = mean(IMF, 2);
    m2(i, :) = min(IMF, [], 2);
    m3(i, :) = max(IMF, [], 2);
    m4(i, :) = std(IMF, 0, 2);
    m5(i, :) = var(IMF, 0, 2);
end    

Note that I removed some temporary variables, avoided the nested loop and preallocated the variables outside the loop. This may decrease the execution time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.