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:
split string and plot

Subject: split string and plot

From: Leyo Joseph

Date: 19 Nov, 2012 21:30:22

Message: 1 of 5

Hello,

I have matlab script to pull out data from a test instrument using TCP/IP.
I got the data "stim_freq" as a string with 501 values separated by comma and "stim_gd" as a string with 501 values with comma separation. Using the following, I separated the string==>
p=regexp(stim_freq,',','split');
pp=regexp(stim_gd,',','split');
Now p and pp are cell arrays. How to plot as x axis and pp as y axis?

Subject: split string and plot

From: Nasser M. Abbasi

Date: 19 Nov, 2012 21:36:37

Message: 2 of 5

On 11/19/2012 3:30 PM, Leyo Joseph wrote:
> Hello,
>
> Now p and pp are cell arrays. How to plot as x axis and pp as y axis?
>


may be

-----------------------
p = {'1','2','3'}; pp={'4','5','6'};
x = str2num(char(p));
y = str2num(char(pp));
plot(x,y,'ro')
-----------------------------

--Nasser

Subject: split string and plot

From: dpb

Date: 19 Nov, 2012 21:46:51

Message: 3 of 5

On 11/19/2012 3:30 PM, Leyo Joseph wrote:
> Hello,
>
> I have matlab script to pull out data from a test instrument using TCP/IP.
> I got the data "stim_freq" as a string with 501 values separated by
> comma and "stim_gd" as a string with 501 values with comma separation.
> Using the following, I separated the string==>
> p=regexp(stim_freq,',','split');
> pp=regexp(stim_gd,',','split');
> Now p and pp are cell arrays. How to plot as x axis and pp as y axis?

Since you want numeric values, rather than regexp(), use textscan instead...

You'll get cell arrays still, but they'll be numeric and you can skip
the num2str() of the other way and just

plot(p{:}, pp{:})

--

Subject: split string and plot

From: Leyo Joseph

Date: 19 Nov, 2012 23:56:15

Message: 4 of 5

dpb <none@non.net> wrote in message <k8e9e0$1du$1@speranza.aioe.org>...
> On 11/19/2012 3:30 PM, Leyo Joseph wrote:
> > Hello,
> >
> > I have matlab script to pull out data from a test instrument using TCP/IP.
> > I got the data "stim_freq" as a string with 501 values separated by
> > comma and "stim_gd" as a string with 501 values with comma separation.
> > Using the following, I separated the string==>
> > p=regexp(stim_freq,',','split');
> > pp=regexp(stim_gd,',','split');
> > Now p and pp are cell arrays. How to plot as x axis and pp as y axis?
>
> Since you want numeric values, rather than regexp(), use textscan instead...
>
> You'll get cell arrays still, but they'll be numeric and you can skip
> the num2str() of the other way and just
>
> plot(p{:}, pp{:})
>
> --

Thanks. Could you please give me a hint on how to proceed with textscan?
The variable "stim_freq " is like (1685000000,1685630000,1686260000,1686890000,1687520000,1688150000,1688780000,.....) and the variable "stim_gd" is like (7.847651617E-009,7.840270671E-009,7.833383973E-009,7.826488771E-009,7.819906752E-009,7.813325228E-009,...).
Basically, I want to plot the elements of stim_freq vs elements of stim_gd.

Subject: split string and plot

From: dpb

Date: 20 Nov, 2012 00:23:40

Message: 5 of 5

On 11/19/2012 5:56 PM, Leyo Joseph wrote:
...

>> Since you want numeric values, rather than regexp(), use textscan
>> instead...
>>
>> You'll get cell arrays still, but they'll be numeric and you can skip
>> the num2str() of the other way and just
>>
>> plot(p{:}, pp{:})
>>
>> --
>
> Thanks. Could you please give me a hint on how to proceed with textscan?
> The variable "stim_freq " is like
> (1685000000,1685630000,1686260000,1686890000,1687520000,1688150000,1688780000,.....)
> and the variable "stim_gd" is like
> (7.847651617E-009,7.840270671E-009,7.833383973E-009,7.826488771E-009,7.819906752E-009,7.813325228E-009,...).
>
...

My version predates textscan() so have to wing it but sotoo---

f=textscan(stim_freq(2:end-1),'%d','delimiter',',');
y=textscan(stim_gd(2:end-1),'%f','delimiter',',');

plot(f{:},y{:})

I took the expedient of skipping over the opening and closing paren's
rather than mucking of the format string to deal with them...

--

Tags for this Thread

No tags are associated with 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