Clear Filters
Clear Filters

Problem changing sheets using xlsread

1 view (last 30 days)
Henry
Henry on 14 Aug 2013
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 Comment
dpb
dpb on 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...

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 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 Comments
Henry
Henry on 16 Aug 2013
Edited: Henry on 16 Aug 2013
Runnning from sheet1:
size_Column3=size(Input_Parameters(:,3))
size_Column4=size(Input_Parameters(:,4))
Current_Table(1,:) = Input_Parameters(:,3) Frequency_Table(1,:) = Input_Parameters(:,4)
Gives:
size_Column3 =
10 1
size_Column4 =
10 1
Current_Table =
65 65 65 65 65 65 65 65 65 65
Frequency_Table =
6 6 6 6 6 12 12 12 12 12
As it should. Then changing to Sheet2:
size_Column3 =
6 1
size_Column4 =
6 1
??? Error using ==> unknown
Subscripted assignment dimension mismatch.
Error in ==> Peak_Value_Seek_2_1 at 64
Current_Table(1,:) = Input_Parameters(:,3)
I don't understand why, given initial_parameters is updating normally, Current_Table isn't being overwritten with the new values?
Image Analyst
Image Analyst on 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);

Sign in to comment.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!