why is my plot blank?

2 Ansichten (letzte 30 Tage)
leah
leah am 19 Feb. 2023
Beantwortet: Star Strider am 19 Feb. 2023
readtable ("LOGGER31.xlsx")
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
ans = 89123×6 table
x_Mills x_Stamp x_Datetime x_thermResistance x_thermResistance_1 x_NaN _______ __________ ________________________ _________________ ___________________ __________ 999 1.6766e+09 {'17-Feb-2023 14:48:30'} 23651 1.49 {0×0 char} 1998 1.6766e+09 {'2023/2/17 14:48:31' } 23651 1.49 {0×0 char} 3000 1.6766e+09 {'2023/2/17 14:48:32' } 23651 1.49 {0×0 char} 3998 1.6766e+09 {'2023/2/17 14:48:33' } 23651 1.49 {0×0 char} 5000 1.6766e+09 {'2023/2/17 14:48:34' } 23651 1.49 {0×0 char} 5999 1.6766e+09 {'2023/2/17 14:48:35' } 23651 1.49 {0×0 char} 6999 1.6766e+09 {'2023/2/17 14:48:36' } 23651 1.49 {0×0 char} 8000 1.6766e+09 {'2023/2/17 14:48:37' } 23651 1.49 {0×0 char} 8999 1.6766e+09 {'2023/2/17 14:48:38' } 23541 1.49 {0×0 char} 9999 1.6766e+09 {'2023/2/17 14:48:39' } 23651 1.49 {0×0 char} 10998 1.6766e+09 {'2023/2/17 14:48:40' } 23651 1.49 {0×0 char} 11999 1.6766e+09 {'2023/2/17 14:48:41' } 23651 1.49 {0×0 char} 12999 1.6766e+09 {'2023/2/17 14:48:42' } 23651 1.49 {0×0 char} 14000 1.6766e+09 {'2023/2/17 14:48:43' } 23651 1.49 {0×0 char} 14998 1.6766e+09 {'2023/2/17 14:48:44' } 23651 1.49 {0×0 char} 16000 1.6766e+09 {'2023/2/17 14:48:45' } 23651 1.49 {0×0 char}
x = LOGGER31(:,"x_Datetime")
Unrecognized function or variable 'LOGGER31'.
y = LOGGER31(:,"x_thermResistance")
plot (x,y)
  2 Kommentare
Walter Roberson
Walter Roberson am 19 Feb. 2023
readtable() does not assign the results to a variable by default.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 19 Feb. 2023
It looks like that the whole imported data is not taken for x and y to plot them. See - e.g.:
D = readtable('DATA_A.csv');
x = D.N;
y = D.V;
plot(x, y, 'k-')
grid on
xlabel('N')
ylabel('V')

Star Strider
Star Strider am 19 Feb. 2023
Try something like this —
LOGGER31 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1300315/LOGGER31.xlsx', 'VariableNamingRule','preserve')
LOGGER31 = 89123×6 table
%Mills %Stamp %Datetime %thermResistance %thermResistance_1 %NaN ______ __________ ________________________ ________________ __________________ __________ 999 1.6766e+09 {'17-Feb-2023 14:48:30'} 23651 1.49 {0×0 char} 1998 1.6766e+09 {'2023/2/17 14:48:31' } 23651 1.49 {0×0 char} 3000 1.6766e+09 {'2023/2/17 14:48:32' } 23651 1.49 {0×0 char} 3998 1.6766e+09 {'2023/2/17 14:48:33' } 23651 1.49 {0×0 char} 5000 1.6766e+09 {'2023/2/17 14:48:34' } 23651 1.49 {0×0 char} 5999 1.6766e+09 {'2023/2/17 14:48:35' } 23651 1.49 {0×0 char} 6999 1.6766e+09 {'2023/2/17 14:48:36' } 23651 1.49 {0×0 char} 8000 1.6766e+09 {'2023/2/17 14:48:37' } 23651 1.49 {0×0 char} 8999 1.6766e+09 {'2023/2/17 14:48:38' } 23541 1.49 {0×0 char} 9999 1.6766e+09 {'2023/2/17 14:48:39' } 23651 1.49 {0×0 char} 10998 1.6766e+09 {'2023/2/17 14:48:40' } 23651 1.49 {0×0 char} 11999 1.6766e+09 {'2023/2/17 14:48:41' } 23651 1.49 {0×0 char} 12999 1.6766e+09 {'2023/2/17 14:48:42' } 23651 1.49 {0×0 char} 14000 1.6766e+09 {'2023/2/17 14:48:43' } 23651 1.49 {0×0 char} 14998 1.6766e+09 {'2023/2/17 14:48:44' } 23651 1.49 {0×0 char} 16000 1.6766e+09 {'2023/2/17 14:48:45' } 23651 1.49 {0×0 char}
x = LOGGER31.('%Datetime');
x{1} = string(datetime(x(1,1),'Format','yyyy/MM/dd HH:mm:ss')); % First Element Has A Different Format
x = datetime(string(x), 'InputFormat',"yyyy/MM/dd HH:mm:ss", 'Format','yyyy/MM/dd HH:mm:ss'); % Convert All To 'datetime'
LOGGER31.('%Datetime') = x % 'LOGGER31' With Consistent '%Datetime'
LOGGER31 = 89123×6 table
%Mills %Stamp %Datetime %thermResistance %thermResistance_1 %NaN ______ __________ ___________________ ________________ __________________ __________ 999 1.6766e+09 2023/02/17 14:48:30 23651 1.49 {0×0 char} 1998 1.6766e+09 2023/02/17 14:48:31 23651 1.49 {0×0 char} 3000 1.6766e+09 2023/02/17 14:48:32 23651 1.49 {0×0 char} 3998 1.6766e+09 2023/02/17 14:48:33 23651 1.49 {0×0 char} 5000 1.6766e+09 2023/02/17 14:48:34 23651 1.49 {0×0 char} 5999 1.6766e+09 2023/02/17 14:48:35 23651 1.49 {0×0 char} 6999 1.6766e+09 2023/02/17 14:48:36 23651 1.49 {0×0 char} 8000 1.6766e+09 2023/02/17 14:48:37 23651 1.49 {0×0 char} 8999 1.6766e+09 2023/02/17 14:48:38 23541 1.49 {0×0 char} 9999 1.6766e+09 2023/02/17 14:48:39 23651 1.49 {0×0 char} 10998 1.6766e+09 2023/02/17 14:48:40 23651 1.49 {0×0 char} 11999 1.6766e+09 2023/02/17 14:48:41 23651 1.49 {0×0 char} 12999 1.6766e+09 2023/02/17 14:48:42 23651 1.49 {0×0 char} 14000 1.6766e+09 2023/02/17 14:48:43 23651 1.49 {0×0 char} 14998 1.6766e+09 2023/02/17 14:48:44 23651 1.49 {0×0 char} 16000 1.6766e+09 2023/02/17 14:48:45 23651 1.49 {0×0 char}
VN = LOGGER31.Properties.VariableNames;
x = LOGGER31.('%Datetime');
y = LOGGER31.('%thermResistance');
figure
plot (x,y)
grid
xlabel(VN{3})
ylabel(VN{4})
The plot was blank because the ‘%Datetime’ values were not converting correctly. The first element converted correctly, however the others were all NaT (‘not a time’), equivalent to NaN for numeric values, since they did not have the same formats as the first element, even though they were valid values, as my code demonstrates.
.

Kategorien

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by