To reply on Icrontic, register now.

It only takes 30 seconds.

Have an account? Sign in for less ads.

Forgot?
rance
Getting settled in
rance
6 Posts

Matlab help for a beginner! - Cell arrays and indexing

Hi All

First off.....I apologize for the lame question.

I'm looking for some matlab help. I have a long data set (1 column, over 200,000 points) and would like to pick out specific 'groups' of data from it. I have a program developed that will do this if I use the input command and manually type my start and end point for the group of data I want. However, since I have a lot of these 'start-end' times, I would like to call in another file that has all of them listed, and my program run through each 'start-end' time.

make sense? i didn't think this would be hard to do, but I'm having considerable trouble!

Any recommendations would be great!
Thanks
Rance
shwaip
elaborate bot
shwaip
5,729 Posts

Re: Matlab help for a beginner!

check out how to use dlmread or csvread.

if you format the start and end times in a file as follows

starttime1, endtime1
starttime2, endtime2
...

and so on.

times = csvread('timefile.csv');

will put the times into a 2-column matrix called 'times'.

Then, if you say times(1,: ), you'll get starttime1 endtime1. If you write these times as indicies to 'timefile.csv', then you can just do the following

indicies = times(1,1):times(1,2);
group = longdataset(indicies);

then you can loop through if you want:
PHP Code:
times csvread('timefile.csv');
for 
i=1:length(times)
  
indicies times(i,1):times(i,2);
  
group hugedata(indicies);
  %do 
stuff with group
end 
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
rance
Getting settled in
rance
6 Posts

Re: Matlab help for a beginner!

Thank you so much for the reply. It helped, and made me realize I am on the right track. I have been using csvread.

Here is what I have based on what you suggested, but still have a similar issue as before:

times = csvread('info_file.csv');
start = times(:,1);
endp = times(:,2);

for i=1:length(times)
indicies=start(i,1):endp(i,2);
group=hugedata(indicies);
%do other stuff with group
end

It seems to do what I need for the last group of start-end times. But doesn't carry on from the first to the next. Any suggestions?

Thanks again.
primesuspect
The Icrontic Guy
primesuspect
27,791 Posts

Re: Matlab help for a beginner!

On a completely unrelated note:

Where on earth are all these Matlab "help me" questions coming from?

Don't get me wrong - I'm really happy that short-media is here for you guys, but it's been driving me nuts - how on earth did our site somehow end up a resource for Matlab help?

Rance, if you don't mind, just to satisfy my curiosity, of course, could you tell me how you found us?

Thanks! Carry on.....
__________________ "I offer my genius to the world, all I ask is you pick up my expenses"
rance
Getting settled in
rance
6 Posts

Re: Matlab help for a beginner!

for me - i guess it was the result of others posting matlab questions. I did a quick google search and some previous matlab questions from this board came up.

Sorry for all the bother. I'll figure out the rest of my problem based on what shwaip has suggested.

Although I haven't posted here before, I've actually been reading threads on this board for awhile.
primesuspect
The Icrontic Guy
primesuspect
27,791 Posts

Re: Matlab help for a beginner!

Oh no, it's not a bother at all! I'm really happy you found us, I was just curious because search stats are sort of a hobby of mine (you could say I have a vested interest ) and if we can optimize things to bring even more people here for matlab help, then I want to learn as much as I can about where the search results are coming from
shwaip
elaborate bot
shwaip
5,729 Posts

Re: Matlab help for a beginner!

Thank you so much for the reply. It helped, and made me realize I am on the right track. I have been using csvread.

Here is what I have based on what you suggested, but still have a similar issue as before:

times = csvread('info_file.csv');
start = times(:,1);
endp = times(:,2);

for i=1:length(times)
indicies=start(i,1):endp(i,2);
group=hugedata(indicies);
%do other stuff with group
end

It seems to do what I need for the last group of start-end times. But doesn't carry on from the first to the next. Any suggestions?

Thanks again.
Hi rance:

once you've assigned start and endp to be vectors, they're one-dimensional. I'm surprised that matlab isn't giving you errors when you try
indicies=start(i,1):endp(i,2)
because endp(i,2) should be out of the index bounds.

just try indicies=start(i):endp(i)

also, just ignore prime. He's just some creepy (old) guy that's always around, for some reason.
primesuspect
The Icrontic Guy
primesuspect
27,791 Posts

Re: Matlab help for a beginner!

Not old yet - give me another month and a half...
rance
Getting settled in
rance
6 Posts

Re: Matlab help for a beginner!

Thanks again shwaip.

This seems to work. indicies will loop through all start-endpoints in the command window, but only show an indicies (1 x specific number matrix) in the workspace - which is the last start-end point.

The last start-endpoint then takes the correct data (based on the start-endpoint) from 'hugedata'.

How would I go about getting all start-endpoints (from hugedata) in one large 'group' matrix . IE

start-end1, start-end2
#,#
#,#
#,#
#,#
shwaip
elaborate bot
shwaip
5,729 Posts

Re: Matlab help for a beginner!

are the lengths of all the start-endpoints the same? If so, you could do this:

PHP Code:
times csvread('timefile.csv');
startp times(:,1);
endp times(:,2);
dataLen startp(1)-endp(1); %get the length of a segment
 
groupmat 
zeros(dataLen,length(times));
 
for 
i=1:length(times)
   
indicies startp(i):endp(i);
   
groupmat(:,i) = hugedata(indicies);
end 
Then, each column will be a shorter group.

But, if each segment isn't the same length:

PHP Code:
%this assumes hugedata is a column
times 
csvread('timefile.csv');
startp times(:,1);
endp times(:,2);
 
groupmat cell(1,length(times));
 
for 
i=1:length(times)
   
indicies startp(i):endp(i);
   
groupmat{i} = hugedata(indicies);  %note the curybraces
end 
Then to access a single group from groupmat, you'd need to use cell indexing:
groupmat{1} would return the hugedata(startp(1):endp(1)) (again, note the curly braces on groupmat).
rance
Getting settled in
rance
6 Posts

Re: Matlab help for a beginner!

shwaip - Just wanted to send out a big thanks! Everything worked out perfectly! Thanks for all the help and speedy replies!

I have never seen the {} feature before! It's great!
rance
Getting settled in
rance
6 Posts

Re: Matlab help for a beginner!

Hey Shwaip

Got another question for ya.

Depending on how many start stop times there are....I will have that # of groupmats (ie {1}, {2}, {3} and so on). Can I take the data from each of these, and put them in one large data set (ie 1,: 2,: and so on)??
shwaip
elaborate bot
shwaip
5,729 Posts

Re: Matlab help for a beginner!

I don't think you can do it unless they are all the same length.
Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 3:13am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.