Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Textscan address a certain row

Subject: Textscan address a certain row

From: Jarred

Date: 19 May, 2011 15:05:04

Message: 1 of 2

I need to textscan specific rows of a notepad file that looks a little like this:

255 145 17 0
296 163 352 0
321 168 166 0
294 183 183 0
311 185 340 0
347 208 315 0
277 225 8 0
388 234 305 0
338 241 142 0
377 248 127 0
....
Let's just say I wanted to access the third row so I could use the first two fields as a plot point. My code looks like this so far:

infotable = ['filename',num2str(e),'_',num2str(f), '.template']; %(not really that important, this is just the file name)

fid = fopen(infotable, 'rt');
C=textscan(fid, '%d %d %d %d');
  
plot(C{1},C{2}, 'o' );


But how do I plot the C{1} and C{2} of a specific row?


Thanks for any help

Subject: Textscan address a certain row

From: Florin Neacsu

Date: 19 May, 2011 16:00:20

Message: 2 of 2

"Jarred" wrote in message <ir3bj0$87k$1@newscl01ah.mathworks.com>...
> I need to textscan specific rows of a notepad file that looks a little like this:
>
> 255 145 17 0
> 296 163 352 0
> 321 168 166 0
> 294 183 183 0
> 311 185 340 0
> 347 208 315 0
> 277 225 8 0
> 388 234 305 0
> 338 241 142 0
> 377 248 127 0
> ....
> Let's just say I wanted to access the third row so I could use the first two fields as a plot point. My code looks like this so far:
>
> infotable = ['filename',num2str(e),'_',num2str(f), '.template']; %(not really that important, this is just the file name)
>
> fid = fopen(infotable, 'rt');
> C=textscan(fid, '%d %d %d %d');
>
> plot(C{1},C{2}, 'o' );
>
>
> But how do I plot the C{1} and C{2} of a specific row?
>
>
> Thanks for any help

Hi,

you can access your data with C{1}(3), C{2}(3) (you mentioned the third row). You could also do
>x=C{1};
>y=C{2};

and just work from there with x and y which are regular vectors, if you are more comfortable with that.

Regards,
Florin

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us