Problem changing sheets using xlsread
조회 수: 1 (최근 30일)
이전 댓글 표시
Hiya,
I'm taking data from a certain sheet in an excel file and then using this in my script.
I'm reading this data using:
[Input_Parameters, Header_Text] = xlsread('Operating Conditions.xls', 'Sheet1');
and then splitting the columns up into different variables:
Current_Table(1,:) = Input_Parameters(:,3);
Frequency_Table(1,:) = Input_Parameters(:,4);
etc. for the relevant columns.
This works fine, but if I want to change the sheet number, to Sheet2 for example, I get the following error message:
Subscripted assignment dimension mismatch.
I think the problem is that sheet1 has a different number of rows to sheet2, and so when the script tries to take the data from the third column and 'put it into' Current_Table, it won't work because of the differing sizes of data.
If I clear the workspace and then run with sheet2, it works fine again, until i try to switch to sheet1.
It's almost as if something is remembering the size of the data and when I try to use a sheet with a differing size to the one ran straight after 'clearing' it rejects it.
Can anyone help me resolve this please?
Thank you in advance
댓글 수: 1
dpb
2013년 8월 15일
Show actual code and error in context instead of describing it...that clear makes a difference implies you're trying the assignment to an existing variable and I'm doubting Excel actually has anything to do with the problem, per se...
답변 (1개)
Image Analyst
2013년 8월 15일
If column 3 on sheet 2 had a different number of rows than it did on sheet 1, then you will have that problem because Current_Table is setup to have the size from sheet #1, which is a different number of rows. You will need to check the size first, and plug in the actual number/range of indexes needed, rather than just use : (colon), which assumes it will be the same.
댓글 수: 2
Image Analyst
2013년 8월 16일
Because Current_Table has 10 rows and you're trying to fill up all 10 rows with a table that's only 6 rows high. Like I said, you'd have to fill only those rows
Current_Table(1, 1 : size_Column3) = = Input_Parameters(:,3);
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!