How can I iterate the excel column data in Simulink (Matlab function block)?

조회 수: 3 (최근 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?

채택된 답변

Kartikay Sapra
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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by