How can I iterate the excel column data in Simulink (Matlab function block)?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Kartikay Sapra
2022-8-24
编辑:Kartikay Sapra
2022-8-24
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!