"Improper index matrix reference" in matlab 2009b

조회 수: 1 (최근 30일)
jenny
jenny 2023년 8월 7일
댓글: jenny 2023년 8월 8일
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
the cyclist
the cyclist 2023년 8월 7일
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.

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

답변 (1개)

Walter Roberson
Walter Roberson 2023년 8월 7일
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
  댓글 수: 1
jenny
jenny 2023년 8월 8일
Thank you for taking time in answering my question.
I referred to the link you mentioned.
But how to send huge data which has text fields in the excel using the actxserver?. In the link it is A= [1 2; 3 4]

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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by