Filter löschen
Filter löschen

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

7 Ansichten (letzte 30 Tage)
function object = readFromXls(ReadFlag)
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;
object =0;
  1 Kommentar
Ahmad Alswalhi
Ahmad Alswalhi am 3 Mai 2024
Bearbeitet: Walter Roberson am 4 Mai 2024
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pavan Sahith
Pavan Sahith am 7 Mai 2024
Bearbeitet: Pavan Sahith am 7 Mai 2024
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


Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by