Email: [email protected]

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/unable to iterate serially through files in a for loop

unable to iterate serially through files in a for loop

PuTI / 2025-01-23
unable to iterate serially through files in a for loop
Matlab News

I am running a matlab for loop to iterate through 30 .csv files and 30 .xlsx files. At each iteration of the for loop, i expect matlab to read the days from the .xlsx file, pass it to the .csv file so the same days can be selected and then do the calculation in the code. The code runs well, but the files saved are not showing the correct answers like when the calculations are done individually for each .mat and .xlsx file at a time. Only the anwers in the first saved for loop file is correct, the others are not what i expect. it looks like matlab is skipping the files or mixing them up in the for loop iteration, as only the first iteration is correct. The files are arranged serially in my working folder, hence i expect the for loop to iterate serially. Attached here are some of three of the files. Also attached here is the code. Please the main point of concern are the for loops which iterates through the .xlsx and .csv files. Thank you.
startIndex = 1;
endIndex = 3;
startIndex1 = 1;
endIndex1 = 3;

filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.csv’);
filelistt = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.xlsx’);
output1 = cell(31,1);
for fileidx = startIndex:endIndex
% for fileidx = 1:numel(filelist)

spectrum = readmatrix(filelist(fileidx).name);
% y = spectrum(2:end,1:4);
% ctm = cell2mat(y)
e = length(spectrum);
[F] = fillmissing(spectrum, ‘linear’);
for fileidx1 = startIndex1:endIndex1
% for fileidx1 = 1:numel(filelistt)
if fileidx == fileidx1
spectrum1 = readmatrix(filelistt(fileidx1).name);
% % trying to extract the 5 quiet days
yy1 = spectrum1(:,1);
% ctm1 = cell2mat(yy1);
rmn1 = F(:,1) == yy1;
sbd1 = F(rmn1, :);
df1 = sbd1(:,4);
dd = size(df1);
yy2 = spectrum1(:,2);
% ctm2 = cell2mat(yy2);
rmn2 = F(:,1) == yy2;
sbd2 = F(rmn2, :);
df2 = sbd2(:,4);
dd = size(df2);
yy3 = spectrum1(:,3);
% ctm3 = cell2mat(yy3);
rmn3 = F(:,1) == yy3;
sbd3 = F(rmn3, :);
df3 = sbd3(:,4);
dd = size(df3);
yy4 = spectrum1(:,4);
% ctm4 = cell2mat(yy4);
rmn4 = F(:,1) == yy4;
sbd4 = F(rmn4, :);
df4 = sbd4(:,4);
dd = size(df4);
yy5 = spectrum1(:,5);
% ctm5 = cell2mat(yy5);
rmn5 = F(:,1) == yy5;
sbd5 = F(rmn5, :);
df5 = sbd5(:,4);
dd = size(df5);
% concatenating of the 5 quiet days
c = [df1,df2,df3,df4,df5];
% mean along horz. line
cm = mean(c,2);
% mean for the entire column
cmm = mean(cm);
crp = repmat(cmm,24,1);
cmm1 = cm-crp;
cmm2 = cmm1.^2;
cmm3 = mean(cmm2);
cmm4 = sqrt(cmm3); %% this is the standard deviation
mc = cm’;
ee = e/24;
con = repmat(mc,1,ee);
cno = con’;
tyc = F(:,4);
tycc = tyc-cno
ty = F(:,1);
% concatenating the time column with the computed tec values.
yt = [ty,tycc];
elseif fileidx <= 10
save([‘C:UsersshedrDownloadstec data2017DOBUM2casc’, num2str(fileidx)],’yt’)
% elseif fileidx <= 20
% save([‘C:UsersshedrDownloadstec data2017DOBUM2frns’, num2str(fileidx)],’yt’)
% elseif fileidx <= 30
% save([‘C:UsersshedrDownloadstec data2017DOBUM2func’, num2str(fileidx)],’yt’)

% we = size(cno)
end
end
% output1{fileidx} = y;
endI am running a matlab for loop to iterate through 30 .csv files and 30 .xlsx files. At each iteration of the for loop, i expect matlab to read the days from the .xlsx file, pass it to the .csv file so the same days can be selected and then do the calculation in the code. The code runs well, but the files saved are not showing the correct answers like when the calculations are done individually for each .mat and .xlsx file at a time. Only the anwers in the first saved for loop file is correct, the others are not what i expect. it looks like matlab is skipping the files or mixing them up in the for loop iteration, as only the first iteration is correct. The files are arranged serially in my working folder, hence i expect the for loop to iterate serially. Attached here are some of three of the files. Also attached here is the code. Please the main point of concern are the for loops which iterates through the .xlsx and .csv files. Thank you.
startIndex = 1;
endIndex = 3;
startIndex1 = 1;
endIndex1 = 3;

filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.csv’);
filelistt = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.xlsx’);
output1 = cell(31,1);
for fileidx = startIndex:endIndex
% for fileidx = 1:numel(filelist)

spectrum = readmatrix(filelist(fileidx).name);
% y = spectrum(2:end,1:4);
% ctm = cell2mat(y)
e = length(spectrum);
[F] = fillmissing(spectrum, ‘linear’);
for fileidx1 = startIndex1:endIndex1
% for fileidx1 = 1:numel(filelistt)
if fileidx == fileidx1
spectrum1 = readmatrix(filelistt(fileidx1).name);
% % trying to extract the 5 quiet days
yy1 = spectrum1(:,1);
% ctm1 = cell2mat(yy1);
rmn1 = F(:,1) == yy1;
sbd1 = F(rmn1, :);
df1 = sbd1(:,4);
dd = size(df1);
yy2 = spectrum1(:,2);
% ctm2 = cell2mat(yy2);
rmn2 = F(:,1) == yy2;
sbd2 = F(rmn2, :);
df2 = sbd2(:,4);
dd = size(df2);
yy3 = spectrum1(:,3);
% ctm3 = cell2mat(yy3);
rmn3 = F(:,1) == yy3;
sbd3 = F(rmn3, :);
df3 = sbd3(:,4);
dd = size(df3);
yy4 = spectrum1(:,4);
% ctm4 = cell2mat(yy4);
rmn4 = F(:,1) == yy4;
sbd4 = F(rmn4, :);
df4 = sbd4(:,4);
dd = size(df4);
yy5 = spectrum1(:,5);
% ctm5 = cell2mat(yy5);
rmn5 = F(:,1) == yy5;
sbd5 = F(rmn5, :);
df5 = sbd5(:,4);
dd = size(df5);
% concatenating of the 5 quiet days
c = [df1,df2,df3,df4,df5];
% mean along horz. line
cm = mean(c,2);
% mean for the entire column
cmm = mean(cm);
crp = repmat(cmm,24,1);
cmm1 = cm-crp;
cmm2 = cmm1.^2;
cmm3 = mean(cmm2);
cmm4 = sqrt(cmm3); %% this is the standard deviation
mc = cm’;
ee = e/24;
con = repmat(mc,1,ee);
cno = con’;
tyc = F(:,4);
tycc = tyc-cno
ty = F(:,1);
% concatenating the time column with the computed tec values.
yt = [ty,tycc];
elseif fileidx <= 10
save([‘C:UsersshedrDownloadstec data2017DOBUM2casc’, num2str(fileidx)],’yt’)
% elseif fileidx <= 20
% save([‘C:UsersshedrDownloadstec data2017DOBUM2frns’, num2str(fileidx)],’yt’)
% elseif fileidx <= 30
% save([‘C:UsersshedrDownloadstec data2017DOBUM2func’, num2str(fileidx)],’yt’)

% we = size(cno)
end
end
% output1{fileidx} = y;
end I am running a matlab for loop to iterate through 30 .csv files and 30 .xlsx files. At each iteration of the for loop, i expect matlab to read the days from the .xlsx file, pass it to the .csv file so the same days can be selected and then do the calculation in the code. The code runs well, but the files saved are not showing the correct answers like when the calculations are done individually for each .mat and .xlsx file at a time. Only the anwers in the first saved for loop file is correct, the others are not what i expect. it looks like matlab is skipping the files or mixing them up in the for loop iteration, as only the first iteration is correct. The files are arranged serially in my working folder, hence i expect the for loop to iterate serially. Attached here are some of three of the files. Also attached here is the code. Please the main point of concern are the for loops which iterates through the .xlsx and .csv files. Thank you.
startIndex = 1;
endIndex = 3;
startIndex1 = 1;
endIndex1 = 3;

filelist = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.csv’);
filelistt = dir(‘C:UsersshedrDownloadstec data2017DOBUM2*.xlsx’);
output1 = cell(31,1);
for fileidx = startIndex:endIndex
% for fileidx = 1:numel(filelist)

spectrum = readmatrix(filelist(fileidx).name);
% y = spectrum(2:end,1:4);
% ctm = cell2mat(y)
e = length(spectrum);
[F] = fillmissing(spectrum, ‘linear’);
for fileidx1 = startIndex1:endIndex1
% for fileidx1 = 1:numel(filelistt)
if fileidx == fileidx1
spectrum1 = readmatrix(filelistt(fileidx1).name);
% % trying to extract the 5 quiet days
yy1 = spectrum1(:,1);
% ctm1 = cell2mat(yy1);
rmn1 = F(:,1) == yy1;
sbd1 = F(rmn1, :);
df1 = sbd1(:,4);
dd = size(df1);
yy2 = spectrum1(:,2);
% ctm2 = cell2mat(yy2);
rmn2 = F(:,1) == yy2;
sbd2 = F(rmn2, :);
df2 = sbd2(:,4);
dd = size(df2);
yy3 = spectrum1(:,3);
% ctm3 = cell2mat(yy3);
rmn3 = F(:,1) == yy3;
sbd3 = F(rmn3, :);
df3 = sbd3(:,4);
dd = size(df3);
yy4 = spectrum1(:,4);
% ctm4 = cell2mat(yy4);
rmn4 = F(:,1) == yy4;
sbd4 = F(rmn4, :);
df4 = sbd4(:,4);
dd = size(df4);
yy5 = spectrum1(:,5);
% ctm5 = cell2mat(yy5);
rmn5 = F(:,1) == yy5;
sbd5 = F(rmn5, :);
df5 = sbd5(:,4);
dd = size(df5);
% concatenating of the 5 quiet days
c = [df1,df2,df3,df4,df5];
% mean along horz. line
cm = mean(c,2);
% mean for the entire column
cmm = mean(cm);
crp = repmat(cmm,24,1);
cmm1 = cm-crp;
cmm2 = cmm1.^2;
cmm3 = mean(cmm2);
cmm4 = sqrt(cmm3); %% this is the standard deviation
mc = cm’;
ee = e/24;
con = repmat(mc,1,ee);
cno = con’;
tyc = F(:,4);
tycc = tyc-cno
ty = F(:,1);
% concatenating the time column with the computed tec values.
yt = [ty,tycc];
elseif fileidx <= 10
save([‘C:UsersshedrDownloadstec data2017DOBUM2casc’, num2str(fileidx)],’yt’)
% elseif fileidx <= 20
% save([‘C:UsersshedrDownloadstec data2017DOBUM2frns’, num2str(fileidx)],’yt’)
% elseif fileidx <= 30
% save([‘C:UsersshedrDownloadstec data2017DOBUM2func’, num2str(fileidx)],’yt’)

% we = size(cno)
end
end
% output1{fileidx} = y;
end for loop, iteration MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Generate ST code from a look-up table with CONSTANT attribute
2025-05-22

Generate ST code from a look-up table with CONSTANT attribute

“no healthy upstream” error when trying to access My Account
2025-05-22

“no healthy upstream” error when trying to access My Account

MATLAB Answers is provisionally back?
2025-05-21

MATLAB Answers is provisionally back?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: [email protected]
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss