Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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 commentaire
Ahmad Alswalhi
Ahmad Alswalhi le 3 Mai 2024
Modifié(e) : Walter Roberson le 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?

Connectez-vous pour commenter.

Réponses (1)

Pavan Sahith
Pavan Sahith le 7 Mai 2024
Modifié(e) : Pavan Sahith le 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

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by