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:
Removing Square brackets from my text

Subject: Removing Square brackets from my text

From: Faraz Afzal

Date: 5 Jul, 2010 17:54:04

Message: 1 of 5

Hi everyone,

I came across a problem and I am unable to workout even after trying with textscan,fscanf, and whatever i can.. I don't know where I am doing wrong.

I have a software that would generate my simulation results in this format,

[[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]


This is just one of the rows of text at some instant t1....And I have similar data for upto tn where n = varies in each simulation and could go upto 1000..

Now i want to scan just the numerical values and assign them to a matrix.

Can anyone show me how would i do that... Rows are messed up with the square brackets..

Regards,
Faraz

Subject: Removing Square brackets from my text

From: Walter Roberson

Date: 5 Jul, 2010 17:57:08

Message: 2 of 5

Faraz Afzal wrote:
> I have a software that would generate my simulation results in this format,
> [[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]

> Now i want to scan just the numerical values and assign them to a matrix.
>
> Can anyone show me how would i do that... Rows are messed up with the
> square brackets..

You could use textscan() with a Delimiter parameter of '[],;' and
MultipleDelimsAsOne set to 1 .

Subject: Removing Square brackets from my text

From: Faraz Afzal

Date: 5 Jul, 2010 18:18:04

Message: 3 of 5

Walter Roberson <roberson@hushmail.com> wrote in message <i0t6j4$46l$1@canopus.cc.umanitoba.ca>...
> Faraz Afzal wrote:
> > I have a software that would generate my simulation results in this format,
> > [[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]
>
> > Now i want to scan just the numerical values and assign them to a matrix.
> >
> > Can anyone show me how would i do that... Rows are messed up with the
> > square brackets..
>
> You could use textscan() with a Delimiter parameter of '[],;' and
> MultipleDelimsAsOne set to 1 .

Still some errors...
I am not even able to move a single line..
even in a one single line i have no progress..
This is what i wrote for a single row above,

S = '[[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]'
KK = textscan(S, '[[],;')

i get an empty cell..

Subject: Removing Square brackets from my text

From: Walter Roberson

Date: 5 Jul, 2010 18:20:29

Message: 4 of 5

Faraz Afzal wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <i0t6j4$46l$1@canopus.cc.umanitoba.ca>...
>> Faraz Afzal wrote:
>> > I have a software that would generate my simulation results in this
>> format,
>> >
>> [[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]
>>
>> > Now i want to scan just the numerical values and assign them to a
>> matrix.
>> > > Can anyone show me how would i do that... Rows are messed up with
>> the > square brackets..
>>
>> You could use textscan() with a Delimiter parameter of '[],;' and
>> MultipleDelimsAsOne set to 1 .
>
> Still some errors...
> I am not even able to move a single line..
> even in a one single line i have no progress..
> This is what i wrote for a single row above,
>
> S =
> '[[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]'
>
> KK = textscan(S, '[[],;')
>
> i get an empty cell..

 >> textscan(S,'%f','Delimiter','[],;','MultipleDelimsAsOne',1)
ans =
     [24x1 double]

Subject: Removing Square brackets from my text

From: us

Date: 5 Jul, 2010 18:38:27

Message: 5 of 5

"Faraz Afzal"
> S = '[[0.990272;0.108886;-0.0866375],[-0.108472;0.994054;0.00949007],[0.0871557;0;0.996195]][7.01034;-0.525157;0][1.0447;5.13572;-3.51292][0.0544432;0.497027;0.458227][-8.15878;0.14572;-2.61607][0.260417;0.273269;-0.470216]'
> KK = textscan(S, '[[],;')
>
> i get an empty cell..

well, of course: this is NOT the correct syntax...
peruse the help, again...

     help textread;
     help textscan;

us

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