Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Ahmad Alswalhi
Ahmad Alswalhi il 3 Mag 2024
Modificato: Walter Roberson il 4 Mag 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?

Accedi per commentare.

Risposte (1)

Pavan Sahith
Pavan Sahith il 7 Mag 2024
Modificato: Pavan Sahith il 7 Mag 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

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by