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!