From: Sherif Kamel on
Dear Colleagues,
I programmed a matlab code to use in postprocessing my numerical analysis results. My code write a text file to certain folder that I sepcified on my computer. The command that I used to do so is the fprintf and the format specified: '%i %i %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f' --> this code works very good and I am able to retrieve the data normally in excel.

When I try to use one of the generated files in another new matlab code to do some manipulation I got stuck. The reason is that when I use the textread command and specify the format the same as the above '%i %i %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f' I got bad formatted string!!! when I change the format for textread command to '%s %s %s %s %s %s %s %s %s %s', it works fine but the problem the array generated is no longer numeric one ; all elements are specified as strings which is quite problematic for my future manipulation.

I wish to know what is my mistake with the fprintf to let matlab generate the data in the files as string elements.
The second thing that I wish to know what is the command that allows me to convert the matrix with string elements to numeric normal matrix array .

Thanks in advance for your help
Sherif
From: Nathan on
On Feb 24, 5:41 pm, "Sherif Kamel" <fo2s...(a)gmail.com> wrote:
> Dear Colleagues,
> I programmed a matlab code to use in postprocessing my numerical analysis results. My code write a text file to certain folder that I sepcified on my computer. The command that I used to do so is the fprintf and the format specified: '%i %i %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f' --> this code works very good and I am able to retrieve the data normally in excel.
>
> When I try to use one of the generated files in another new matlab code to do some manipulation I got stuck. The reason is that when I use the textread command and specify the format the same as the above '%i %i %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f'  I got bad formatted string!!! when I change the format for textread command to  '%s %s %s %s %s %s %s %s %s %s', it works fine but the problem the array generated is no longer numeric one ; all elements are specified as strings which is quite problematic for my future manipulation.
>
> I wish to know what is my mistake with the fprintf to let matlab generate the data in the files as string elements.
> The second thing that I wish to know what is the command that allows me to convert the matrix with string elements to numeric normal matrix array .
>
> Thanks in advance for your help
> Sherif

To convert a string to a number,
doc str2num
or
doc str2double


-Nathan
From: Walter Roberson on
Sherif Kamel wrote:
> The command that I used to do so is the
> fprintf and the format specified: '%i %i %6.3f %6.3f %6.3f %6.3f %6.3f
> %6.3f %6.3f %6.3f' --> this code works very good and I am able to
> retrieve the data normally in excel.
> When I try to use one of the generated files in another new matlab code
> to do some manipulation I got stuck. The reason is that when I use the
> textread command and specify the format the same as the above '%i %i
> %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f' I got bad formatted
> string!!!

When you use textread() you cannot use %i format.

You should be upgrading to textscan(), which supports formats such as
%d16 and %u32 .