why is my plot blank?

2 次查看(过去 30 天)
leah
leah 2023-2-19
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 个评论
Stephen23
Stephen23 2023-2-19
Maybe your data consists only of NaNs, or perhaps you are plotting only one point (which by default has no marker... no idea whay that is the default). In any case, without your data we cannot do much more than guess.
Walter Roberson
Walter Roberson 2023-2-19
readtable() does not assign the results to a variable by default.

请先登录,再进行评论。

回答(2 个)

Sulaymon Eshkabilov
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 2023-2-19
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.
.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by