Different length data - not able to use structures, matrix, or eval. What can I use?
13 views (last 30 days)
Show older comments
I'm performing some data analysis over and over on different data sets.
The initial data set is a matrix, where each column is a variable over time. I'm extracting two of these columns (time and mph) and performing analysis on them.
I am doing this for many data sets. However, each data set has a different number of rows (it depends on how long the simulation was running)
So I cannot create a matrix called 'time' with each column being a different data set as the data sets are different lengths. I have the same problem with structures.
I have not been able to get 'eval' (in order to create named variables such as time_1, time_2) to work with arrays.
Is there any thing else I can use?
0 Comments
Accepted Answer
Image Analyst
on 1 Feb 2013
You say " However, each data set has a different number of rows (it depends on how long the simulation was running). So I cannot create a matrix called 'time' with each column being a different data set as the data sets are different lengths." I say, "Why not?" You have a data set with different number of rows - I'll assume it's a 2D matrix with R rows and C columns. I don't care what R is, if you want to extract out a column, say column #2, just do this:
column2vector = yourMatrix(:, 2);
Do the same for any other columns you need, then process them all. Then you're done with this data set, and you move on to process the next data set. what's the problem processing this way, if any?
More Answers (1)
Jason Ross
on 1 Feb 2013
Edited: Jason Ross
on 1 Feb 2013
Why can't you use operators like colon or end to allow data of different sizes to be imported? You can effectively say "give me all the data in this row" or "give me all the data starting from X and then stopping 5 away from the end"
Example:
>> m = magic(5)
m =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> out1 = m(4,:)
out1 =
10 12 19 21 3
>> out2 = m(:,4)
out2 =
8
14
20
21
2
>> out3 = m(2,1:end-2)
out3 =
23 5 7
0 Comments
See Also
Categories
Find more on Variables 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!