MATLAB Answers

Hi. I want to automate a process which consists of 3 steps. 1. Read the data from excel file and extract the necessary data alone. 2. Run the data and output plots. 3. Store the results (workspace) in a specified folder in my computer.

3 views (last 30 days)
Gokul Prassad
Gokul Prassad on 9 Dec 2019
Commented: Stephen Cobeldick on 10 Dec 2019
1. Read the data from excel file and extract the necessary data alone.
2. Run the data and output plots.
3. Store the results (workspace) in a specified folder in my computer.
Also, I want to do a batch simulation. That is run a code to read and perform the above three steps for multiple excel files at a time (or one after another automatically).
Please help

  2 Comments

Raj
Raj on 10 Dec 2019
"extract the necessary data alone" - What is necessary data?
"Run the data" - What 'run' do you want to do?
"output plots" - What type of plot?
"perform the above three steps for multiple excel files at a time " - You will have to mention the file names and it should be a pattern that can be put in a loop.
Your question is way too vague. Atlease share a sample file and clearly specify what you want to do with it.
Stephen Cobeldick
Stephen Cobeldick on 10 Dec 2019
Gokul Prassad's "Answer" moved here:
Hi Raj,
Thank you for your response.
I am doing analysis of various vehicle data like mass, accelertation, speed, torque,...
Consider I have 10 sets of data (10 vehicles) in 10 sheets of a single MS Excel file.
I want to plot Time vs Speed, Time vs Torque..... plots for each vehicle.
I want to call the master excel file into matlab, read/run the data in each sheet and save the workspace of each sheet in a specific folder.
At the end of the simulation, I want 10 result folders containing the workspace of 10 vehicles.
Hope I am clear.
Looking forward to your response.

Sign in to comment.

Accepted Answer

Raj
Raj on 10 Dec 2019
Edited: Raj on 10 Dec 2019
"I want to call the master excel file into matlab, read/run the data in each sheet and save the workspace of each sheet in a specific folder"
sheets = sheetnames('C:\Users\User\Data.xlsx') % Put your file path here
for ii = 1:length(sheets)
data{1} = xlsread('C:\Users\User\Data.xlsx',['Sheet'num2str(ii)]) % Read data from one sheet at a time
save data % Save workspace
mkdir(['Vehicle' num2str(ii)]) % Create new folder with vehicle number as folder name
movefile('data',['Vehicle'num2str(ii)]); % Move data to newly created folder
clear data % clear data from workspace and repeat for all the sheets.
end
It is not clear how you want the plot part. Do you want to save the plots, create new plots for each vehicle , overwrite or hold on? Whatever be the case, now that you have the data in workspace, extract the relevant data and plot according to your requirement.

  2 Comments

Stephen Cobeldick
Stephen Cobeldick on 10 Dec 2019
Gokul Prassad's "Answer" moved here:
Hi Raj,
I am getting the following error.
Error: File: batch_sim.m Line: 3 Column: 105
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
num2Str is shown as invalid expression ! in line 3 and 6.
I replaced the parentheses with brackets and still get the same error

Sign in to comment.

More Answers (0)

Sign in to answer this question.