Problem changing sheets using xlsread
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
dpb
am 15 Aug. 2013
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...
Antworten (1)
Image Analyst
am 15 Aug. 2013
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 Kommentare
Image Analyst
am 16 Aug. 2013
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);
Siehe auch
Kategorien
Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!