"Improper index matrix reference" in matlab 2009b
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I got this error "Improper index matrix reference" in matlab 2009b after importing the excel sheet which has tescase inputs
%Below is how I'm reading the excel in matlab 2009b
[TC_data1,TC_data2,TC_data] = xlsread('SSL_MasterTestList.xlsx','TestCase','C4:AQ17');
%Select test case #
prompt = 'Input TestCase number to Run: ';
TC_RunNum =input(prompt);
%collects data for test case for all inputs
TC_size = size(TC_data);
TC_row = TC_size(1);
TC_col = TC_size(2);
TC_len = length(TC_data(:,TC_RunNum).Variables);
Improper index matrix reference. Error occured in "TC_len"
Can anyone suggest how to resolve?
Thank you!
1 comentario
the cyclist
el 7 de Ag. de 2023
Can you upload the input data file (or a small sample that replicates the error in your code)? You can use the paper clip icon in the INSERT section of the toolbar.
Respuestas (1)
Walter Roberson
el 7 de Ag. de 2023
TC_data is the third output of xlsread(), and the third output of xlsread() is always a cell array.
So in
TC_len = length(TC_data(:,TC_RunNum).Variables);
then the TC_data(:,TC_RunNum) is going to return a cell array. You are then trying to do dot indexing of a cell array, which is not possible.
If you had switched from () indexing to {} indexing, such as TC_data{:,TC_RunNum}.Variables then you would be extracting from the cell array and trying to dot index that. You could potentially run into sizing problems if you did that, since you might (probably would) be expanding multiple rows with the : indexing, but if there only happened to be one row, then the TC_Data{:,TC_RunNum} could potentially refer to a single object. You would then in that particular case be trying to dot index a single object. But in this particular case you can predict that would fail because xlsread() never returns cells that contain structs or objects.
xlsread() does not return objects that can be used to refer directly to cells. It cannot for example be used to read out the format settings of a cell, or the macros. If you need to deal with that level, then you need to use actxserver; see the example at https://www.mathworks.com/matlabcentral/answers/94822-are-there-any-examples-that-show-how-to-use-the-activex-automation-interface-to-connect-matlab-to-ex
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!