1

I have 1x14 char output

A = '   3691/1784  '

What I want to get is

P = 3691

Q = 1784

I have tried the following as explained in another answer here:Specify decimal separator for .dat file in matlab

output=str2double(strrep(P,'/','.'))

But the output is 3612.1784.

Any help will be highly appreciated.

Community
  • 1
  • 1
Omer
  • 105
  • 12

2 Answers2

2

Try this:

output = str2double(regexp(A, '\d+', 'match'));

Or, if the numbers may contain a decimal part,

output = str2double(regexp(A, '\d+(\.\d*)?', 'match'));
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
1

Using strsplit and deal:

output = deal(str2double(strsplit(A,'/')))

Might be overkill for this case but that's an alternative haha

Benoit_11
  • 13,905
  • 2
  • 24
  • 35