Data is not storage when running loop
Show older comments
hello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met'
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, '.');
but if I run my script with Data1&2 the output is different and I get less data points

I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf('select folder containing data files\n');
currentpath=pwd; %%
datapath=uigetdir('','Select Data Folder'); %%
if (datapath == 0)
fprintf('Data directory was not selected...script will be terminated\n\n');
return
end
prompt = 'Do you want to export data as .xlsx?';
save_data_excel = questdlg(prompt,'Save','Yes','No','Yes');
cd(datapath); %%
files=dir('@*.mat'); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf('Progress: %d/%d\n\n',i, num_files)
load(files(i,1).name)
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165%% sensor signal
Epm_nEngallc1_3(j,1) = Epm_nEng(j); %% get engine speed if: engine speed is higher than 0 and if sensor signal > 0.165
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j); %% get sensor signal if: engine speed is higher than 0 and if sensor signal > 0.165
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
end
3 Comments
Epsilon
on 13 Sep 2024
Hi, Can you please share the datafiles. It would help us understand the issue better.
Image Analyst
on 13 Sep 2024
Edited: Image Analyst
on 13 Sep 2024
Looks like you blew right past the posting guidelines. If you have any more questions, then attach your 3 data mat files (data01, data02 and data05) with the paperclip icon after you read this:
It's not obvious from your two plots that data05 has fewer points in it than data01 combined with data02.
And how are you plotting? I don't see plot() or scatter() in your code.
And put in some comments! We have no idea what all those variables mean. Help us to help you.
And don't use cd():
Use fullfile() instead.
A-Rod
on 13 Sep 2024
Accepted Answer
More Answers (1)
Walter Roberson
on 13 Sep 2024
0 votes
You set your various arrays conditionally. We should not be surprised if the arrays come out different lengths.
You do not clear the arrays between for i iterations. The arrays are going to stay the same size as they were set in the previous iteration, with entries going unused and maintaining their previous values, unless it just so happens that the second round happens to need more entries in the arrays.
Overall, you should expect chaos in the size of the arrays.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!