필터 지우기
필터 지우기

i want to make MATLAB function in Simulink to read one cell from excel sheet every period of time

조회 수: 3 (최근 30일)
function object = readFromXls(ReadFlag)
coder.extrinsic('readcell');
coder.extrinsic('str2num');
coder.extrinsic('cellfun');
coder.extrinsic('cell2mat');
data = 0;
object = 0;
if ReadFlag == 1
excelFilePath = 'YOLO_Object_Type.xlsx';
% Read data from the Excel file
data = cell2mat(excelFilePath);
%iwant = cellfun(@cell2mat,data)
object = data;
else
object =0;
end
  댓글 수: 1
Ahmad Alswalhi
Ahmad Alswalhi 2024년 5월 3일
편집: Walter Roberson 2024년 5월 4일
the error :
Brace indexing is not supported for variables of this type. Error in cell2mat.m (line 42) cellclass = class(c{1}); Error in 'untitled/MATLAB Function' (line 18)
how can i fix that ?
or is the other way to do this function?

댓글을 달려면 로그인하십시오.

답변 (1개)

Pavan Sahith
Pavan Sahith 2024년 5월 7일
편집: Pavan Sahith 2024년 5월 7일
I see that you are trying to import data from an Excel file processing within a MATLAB function block but it seems you've encountered an error along the way.
The error message you're seeing, "Brace indexing is not supported for variables of this type," is due to an incorrect use of the 'cell2mat' function on a string variable (excelFilePath) rather than on a cell array.
The ' cell2mat ' function is designed to convert cell arrays of numeric values or strings into a regular numeric array or character array, respectively. However, in your code, you are attempting to use ' cell2mat ' on a string that represents the file path, which is not a cell array.
To fix the error,using the ' readcell ' function can help to read the contents of the Excel file into a cell array.
data = readcell(excelFilePath);
The readcell function reads the Excel file and stores its content in a cell array named data.
The following MathWorks documentation helps you to know more about ' readcell ' and ' cell2mat '
Hope this helps you in moving forward

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by