regexprep resolve a comma value from a string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

regexprep resolve a comma value from a string

hxchrist123
Hallo, i stuck at the following problem.
I have a Output-cell wich has the following form:

Output{8}=real:temp:297,15

My goal is to have just the value of 297,15.
With
Temp=str2num(regexprep(Output{8},'\D+', ''));
i got just the numbers 29715.
The comma is deleted. How I can I resolve the complete comma number?

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

NJank
On Jun 9, 2017 6:25 AM, "hxchrist123" <[hidden email]> wrote:
Hallo, i stuck at the following problem.
I have a Output-cell wich has the following form:

Output{8}=real:temp:297,15

My goal is to have just the value of 297,15.
With
Temp=str2num(regexprep(Output{8},'\D+', ''));
i got just the numbers 29715.
The comma is deleted. How I can I resolve the complete comma number?

Thank you.


You're finishing with a str2num. I don't think that will ever output "num,num". What sort of output do you want, a string? Or a number? Or a 1x2 number array? Or...?

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

hxchrist123
Hi,
I would prefer to have as a number, double format.
thx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

NJank
On Jun 9, 2017 6:58 AM, "Nicholas Jankowski" <[hidden email]> wrote:


On Jun 9, 2017 6:34 AM, "hxchrist123" <[hidden email]> wrote:
Hi,
I would prefer to have as a number, double format.
thx

Ok, so for a number like 273,15, what exactly would you want? You got a double format number: 27315

Forgot the reply-all


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

hxchrist123
Sorry, my mistake,
regarding the format,I take what i get.

BR
Chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

NJank
On Jun 9, 2017 7:07 AM, "hxchrist123" <[hidden email]> wrote:
Sorry, my mistake,
regarding the format,I take what i get.

Wait, "273,15". The comma is the radix? Like 273.15? Sorry, I'm thinking like an American and thought it was a pair of two different numbers: 275 and 15. Hence my confusion about what you wanted.

I personally don't know if there are locale options to make this easier. Octave and Matlab generally expect a . instead of a , as a decimal separator.  You could find/replace . for , in your data, then i think the import should work as you want.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

Philip Nienhuis
In reply to this post by hxchrist123
hxchrist123 wrote
Hallo, i stuck at the following problem.
I have a Output-cell wich has the following form:

Output{8}=real:temp:297,15

My goal is to have just the value of 297,15.
With
Temp=str2num(regexprep(Output{8},'\D+', ''));
i got just the numbers 29715.
The comma is deleted. How I can I resolve the complete comma number?
A regexp along the lines of

cell2mat (regexp ("real:temp:297,15", '.+?([\d\.,]+)', "tokens"))
ans =
{
  [1,1] = 297,15
}

should do the trick.

Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

hxchrist123
Hi Philip, many thanks for your help.
unfortunately the 297,15 is not a fixed value it changes from file to file of my 'Output{8}' cell variable.
I read in many files and the value of Output{8} changes....

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

hxchrist123
In reply to this post by NJank
Hi Nich,
If i run my code, there is neither a comma or a point.

Output{8}=real:temp:297,15

if i would transform Output{8} in that way, that i get
Output{8}=real:temp:297.15

when i run
Temp=str2num(regexprep(Output{8},'\D+', ''));  
the point or comma of Output{8} is gone and I always get:
29715. But I need this comand to filter out the string (real:temp:).


Regards,
Chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

Philip Nienhuis
In reply to this post by hxchrist123
hxchrist123 wrote
Hi Philip, many thanks for your help.
unfortunately the 297,15 is not a fixed value it changes from file to file of my 'Output{8}' cell variable.
I read in many files and the value of Output{8} changes....
Apparently you didn't understand that the example I supplied isn't meant to be followed literally. It is meant to show what kind of regexp you need.
I think it'll do a fine job as far as number field containing commas goes.

Maybe you can show a larger sample of the output you expect to be processed?

Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: regexprep resolve a comma value from a string

hxchrist123
Yes, sorry phillip, it works.
Many thanks.
Loading...