Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

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

All Categories

  • Visual Paradigm
  • IBM
  • 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

  • Visual Paradigm
  • IBM
  • 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/nested loops to find values then execute commands

nested loops to find values then execute commands

PuTI / 2025-01-16
nested loops to find values then execute commands
Matlab News

I have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
endI have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
end I have written a script to find the maximum and minimum values of 4 time series and then truncate each time series to these values as they are all of different length.
I want it to record the maximum and minimum values of all the time series first (lines 15-19), then after that store the overall smallest and largest values to new variables (lines 20-23).
At the moment, its constantly updating variables as it loops through, so its not using the overall smallest/largest values to truncate the time series.
I have tried putting lines 15-19 in another loop so it executes this first, but it doesnt seem to make any difference. Can anybody help?
%import all the csv files in the folder
csvFiles = dir(fullfile(folderPath, ‘*.csv’));
%read in all the csv files
for i = 1:length(csvFiles)
%get the individual file pathway
csvFilePath = fullfile(folderPath, csvFiles(i).name);
%read the file in
data = readmatrix(csvFilePath);
%remove nan’s from the timeseries
data = data(~any(isnan(data), 2), :);
%remove non-unique datapoints from the timeseries
[~, id] = unique(data(:,1)) ;
data = data(id,:);
for a = 1:length(csvFiles)
%find and save the maximum value of all the time series
maxVal(1) = max(data(:,1));
%find and save the minimum value of all the time series
minVal(1) = min(data(:,1));
%find and save the mean dt of all the time series
dt(1) = mean(diff(data(:,1)));
end
%find the time series that ends soonest
smallestMaxValue = min(maxVal)
%find the time series that starts latest
largestMinValue = max(minVal)
%truncate all the time series to the shortest one
truncateRow = find(data(:,1) > smallestMaxValue, 1, ‘first’); %find the index of the first value in the first column when the shortest time series is exceeded
if ~isempty(truncateRow)
truncatedData = data(1:truncateRow-1, :); %if there is a value in truncateRow, then truncate the dataset up to this point
else
truncatedData = data; %if there is no value in truncateRow (e.g. shortest time series), then leave the data as it is
end
end for loop, loop, nested loop 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: helpdesk@telkomuniversity.ac.id
  • 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