How can I iterate the excel column data in Simulink (Matlab function block)?
4 views (last 30 days)
Show older comments
jiyong park
on 20 Aug 2022
Commented: jiyong park
on 24 Aug 2022
I would like to import data one by one from excel(.xlsx) to Simulink.
With readtable or readcell, I can call a group of data.
But I would like to update the data in excel one by one automatically.
For example,
In loop :
I import the data in Excel A1, and I apply my function.
secondly the data in Excel A2, and I apply my function. A3, A4, A5..
In Python, I can use like this :
sheet1.cell(row=i+1, column= 1, value= x_in_data[0])
so that I can easily apply the iteration.
However, in Simulink Matlab function block, The readcell command is actually calling the string like this.
M = readcell('airlinesmall_subset.xlsx','Sheet','2007','Range','G2:I11')
What should I do?
0 Comments
Accepted Answer
Kartikay Sapra
on 24 Aug 2022
Edited: Kartikay Sapra
on 24 Aug 2022
The following function 'xlscol' from File Exchange converts an integer to corresponding Excel column:
Then, you can iterate using(assuming first row is for column titles):
for i = 2:numOfRows
for j = 1:numOfColumns
cell_ij = xlscol(j) + string(i)
M = readcell('airlinesmall_subset.xlsx','Sheet','2007','Range', cell_ij + ":" + cell_ij)
end
end
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!