MATLAB Answers

0

STRING ARRAY TO NUMERIC VALUES ( I want to change the array's type to plot the graph, even though I use double function or str2num that doesn't change anything and it still string)

Capture.PNG

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by Amine ELMOUATAMID on 19 Apr 2019
 Accepted Answer

For i=1:rowFr(1,1) new_frequency(i,1)=str2double(frequency(i,1)); And it works

  1 Comment

This is less efficient than my proposed answer.

Sign in to comment.


Answer by Walter Roberson
on 19 Apr 2019

new_frequency(1:rowRPM(1,1)) = str2double(frequency(1:rowRPM(1,1)));
In the special case where you are converting all of the entries, then you can use
frequency = str2double(frequency);
but if rowRPM(1,1) is not equal to the number of elements in frequency, then you need to write to a new location.
In particular, you cannot work the way you are doing now, converting an entry and writing it back to the same array. The string() class will detect that you are storing a number in a string location, and will helpfully format the number as a string and store the string.

  0 Comments

Sign in to comment.