How i creat Costomer fscanf?

Hellow,
I want fscanf a text file same as attech file with the command below:
%%
fileID= fopen('sol2.txt');
sizez=[2,inf];
T=fscanf(fileID,'%f %f,sizez)
fclose(fileID);
%%
But it raeds only 2 Array while i want all of array , readed
How is it possible??

 Risposta accettata

Stephen23
Stephen23 il 24 Gen 2023
Modificato: Stephen23 il 24 Gen 2023
format long
M = readmatrix('sol2.txt', 'Delimiter',{' ','∠'}, 'MultipleDelimsAsOne',true, 'TrimNonNumeric',true)
M = 25×3
0 3.000000000000000 0 0.000250000000000 3.000000000000004 0 0.000500000000000 3.000000000000007 0 0.000750000000000 3.000000000000011 0 0.001000000000000 3.000000000000014 0 0.001250000000000 3.000000000000017 0 0.001500000000000 3.000000000000021 0 0.001750000000000 3.000000000000024 0 0.002000000000000 3.000000000000028 0 0.002250000000000 3.000000000000031 0

Più risposte (1)

Arif Hoq
Arif Hoq il 24 Gen 2023
use readtable function
a=readtable("sol2.txt");

3 Commenti

Majid Majid
Majid Majid il 24 Gen 2023
thanks, but i don't want it is same as follow:
0 {'3.000000000000000E2∠0.000000000000000E0°'}
0.025 {'3.000000000000004E2∠0.000000000000000E0°'}
0.05 {'3.000000000000007E2∠0.000000000000000E0°'}
0.075 {'3.000000000000011E2∠0.000000000000000E0°'}
I want same as follow:
0 0.25 0.5
300 300.0000000004 300.00000000007
I mean, it does not have a plus symbol.
what i do??
thanks
a=table2cell(readtable("sol2.txt"));
f=split(a(:,2),'E2');
g=cell2table(f(:,1));
h=table(a(:,1),table2array(g));
Majid Majid
Majid Majid il 24 Gen 2023
very thanks Arif;
result:
{[ 0]} {'3.000000000000000E2'}
{[0.0250]} {'3.000000000000004E2'}
{[0.0500]} {'3.000000000000007E2'}
{[0.0750]} {'3.000000000000011E2'}
{[0.1000]} {'3.000000000000014E2'}
{[0.1250]} {'3.000000000000017E2'}
{[0.1500]} {'3.000000000000021E2'}
now , i should return value of {} to double,same as matris
i think can do it,
very thanks

Accedi per commentare.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by