Issue with table data creating strings and recognising as numbers
9 ビュー (過去 30 日間)
古いコメントを表示
I'm working on my minor disseration project - this isn't a necessary step at all, I'm doing it as an attempt to get extra credit. I used MATLAB for my third year disseration last year and imported data in a similar way and did not have this issue. Imported data from excel.
I know why the date isn't working as it isn't a conventional number (a way to convert this would be very helpful also? without editing the excel file if possible) but I don't understand why the others are being processed as strings.
I tried using str2double to fix this but my graph still is empty in terms of numbers so the issue is MATLAB not recognising what I'm giving it as numbers.
I have attached the .mat files.
Any help would be appreciated.
function MAVENdata
a = open('10-9-17 cmes.mat');
b = open('4-8-16 cme.mat');
% import data and convert into an array
c = table2array(a.cmes100917);
d = table2array(b.Untitled);
datec=c(:,1));
nTxc=c(:,2));
nTyc=c(:,3));
nTzc=c(:,4));
nTc=c(:,5));
dated=d(:,1));
nTxd=d(:,2));
nTyd=d(:,3));
nTzd=d(:,4));
nTd=d(:,5));
subplot(2,1,1)
plot(datec, nTxc,'k'); hold on;
plot(datec, nTyc,'r'); hold on;
plot(datec, nTzc,'g'); hold on;
plot(datec, nTc,'b'); hold on;
ylabel('MAG (nT)');
xlabel('Timescale');
grid on
hold off;
end
1 件のコメント
Walter Roberson
2018 年 11 月 21 日
open() of aa mat file brings up aa variable import dialog if II recall correctly . load() would seem to be more appropriate .
採用された回答
Cris LaPierre
2018 年 11 月 21 日
編集済み: Cris LaPierre
2018 年 11 月 21 日
What version of MATLAB are you using? If possible, I'd recommend you take advantage of some of the newer features. In particular, I'd recommend datetimes and tables. I modified your mat files back to spreadsheets. Here's how I would implement your code (and it automatically handles the dates).
opts = detectImportOptions('cmes040816.xlsx');
opts = setvartype(opts,'timetagyyyyMMddTHHmmssSSS','datetime');
opts = setvaropts(opts,'timetagyyyyMMddTHHmmssSSS','InputFormat','uuuu-MM-dd''T''HH:mm:ss.SSS');
data16 = readtable('cmes040816.xlsx',opts);
data17 = readtable('cmes100917.xlsx',opts);
data16.Properties.VariableNames = {'date','nTx','nTy','nTz','nT'};
data17.Properties.VariableNames = {'date','nTx','nTy','nTz','nT'};
hold on
plot(data16.date, data16.nTx,'k');
plot(data16.date, data16.nTy,'r');
plot(data16.date, data16.nTz,'g');
plot(data16.date, data16.nT,'b');
hold off;
ylabel('MAG (nT)');
xlabel('Timescale');
grid on
6 件のコメント
Cris LaPierre
2018 年 11 月 21 日
re date16.date - that was a typo. It should be data16.date. I've corrected the code above.
その他の回答 (1 件)
Brian Hart
2018 年 11 月 21 日
Hi Hannah,
Try replacing, for example,
nTxc=c(:,2));
with
nTxc=a.cmes100917(:,2).mag_magnetic_field_mso_xnT;
(I used tab completion rather than typing the whole field name).
This gives me a nTxc variable of type double, and with
plot(nTxc,'k')
I get
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!