Create plot (fig file) from text file

I am using the below code to import data from text file. The code is working, but the .Fig file are very slow afterwards
Is the code ok, or is there a better way
datafile = 'Test_1_pre_test_with_Prose_Fan_Load_streng_1_error_at_8_procent_115222_230119_TEST_1.txt';
T = readtable(datafile,'Format','auto');
T1 =T;
hold on
t = T1.TIME;
P = T1.Properties.VariableNames(2:end);
for K = 1 : length(P)
fn = P{K};
plot(t, T1.(fn), 'DisplayName', fn);
end
hold off
set(gcf, 'visible', 'on')
legend show

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de En. de 2023
T = readtable(datafile,'Format','auto');
P = string(T.Properties.VariableNames) ;
plot(T, P(1), P(2:end)) ;
legend show

7 comentarios

I am trying to read numeric values. So i STRING correct?
"TIME","M101 POWER [KW]","M102 POWER [KW]","M103 POWER [KW]","M104 POWER [KW]","M105 POWER [KW]","M106 POWER [KW]","M107 POWER [KW]","M108 POWER [KW]","M109 POWER [KW]","M110 POWER [KW]","M111 POWER [KW]","M112 POWER [KW]","M113 POWER [KW]","STRING 1 [A]","STRING 2 [A]","DC CABINET DC OUTPUT [A]","VFD AC OUTPUT [VAC]","DC CABINET DC OUTPUT [VDC]","VFD DC INPUT [VDC]","STRING 1 [VDC]","STRING 2 [VDC]"
+0.000000000E+000,-4.00000E-002,-1.00000E-002,-2.00000E-002,-5.00000E-002,+6.11600E+000,-3.75000E-002,-2.50000E-002,-1.25000E-002,+0.00000E+000,-3.75000E-002,-2.50000E-002,-3.75000E-002,+1.25000E-002,+5.00000E-001,+0.00000E+000,+8.82500E+001,+5.29000E+002,+5.26500E+002,+5.23500E+002,+4.23500E+002,+4.22000E+002
+2.000000000E-003,-4.00000E-002,-1.00000E-002,-2.00000E-002,-6.00000E-002,+6.22600E+000,-5.00000E-002,-1.25000E-002,-1.25000E-002,+0.00000E+000,-1.25000E-002,-1.25000E-002,-3.75000E-002,+1.25000E-002,+5.00000E-001,+2.50000E-001,+1.38250E+002,+5.28500E+002,+5.33500E+002,+5.24000E+002,+4.23500E+002,+4.22000E+002
+4.000000000E-003,-2.00000E-002,-3.00000E-002,-3.00000E-002,+0.00000E+000,+6.42400E+000,-5.00000E-002,-3.75000E-002,+0.00000E+000,-1.25000E-002,-2.50000E-002,-1.25000E-002,-3.75000E-002,+1.25000E-002,+5.00000E-001,+2.50000E-001,+1.22000E+002,+5.26500E+002,+5.36500E+002,+5.24000E+002,+4.23500E+002,+4.22000E+002
Walter Roberson
Walter Roberson el 23 de En. de 2023
Yes. string() is being applied to a cell array of character vectors that hold the field names. string() is not being applied to the numeric content.
Steen
Steen el 23 de En. de 2023
Ok, thanks. But I get the below error when I try to save the .Fig file after it has be generated
Walter Roberson
Walter Roberson el 23 de En. de 2023
Try a shorter file name.
Generally speaking it is often more robust to save files to the local system and copy the resulting file to the network file system,instead of saving directly to the network
I does not help to make the the file name shorter. But if I save the .Fig file after it is created by my first code, there is no problem. but when I use the below code, I get the save error
datafile = 'Test_1_pre_test_with_Prose_Fan_Load_streng_1_error_at_8_procent_115222_230119_TEST_1.txt';
T = readtable(datafile,'Format','auto');
P = string(T.Properties.VariableNames) ;
plot(T, P(1), P(2:end)) ;
I might be because of file size. If I make a shorter file, I can save it. But I cant change the file size og why can do you think I can save the file, when using the below code
datafile = 'Test_1_pre_test_with_Prose_Fan_Load_streng_1_error_at_8_procent_115222_230119_TEST_1.txt';
T = readtable(datafile,'Format','auto');
T1 =T;
hold on
t = T1.TIME;
P = T1.Properties.VariableNames(2:end);
for K = 1 : length(P)
fn = P{K};
plot(t, T1.(fn), 'DisplayName', fn);
end
hold off
set(gcf, 'visible', 'on')
legend show

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2022b

Preguntada:

el 19 de En. de 2023

Comentada:

el 31 de En. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by