필터 지우기
필터 지우기

How to delete columns from something that isn't a matrix

조회 수: 3 (최근 30일)
William Campbell
William Campbell 2019년 1월 15일
편집: madhan ravi 2019년 1월 15일
I've got some data that I need columns deleting from, specificially 3,4,5,9,10,12,13,14 but whenever I try the following code, with data set A, I get the answer "Deletion requires an existing variable."
A(:,[3 4 5 9 10 12 13 14])=[];
Is this because my data is not technically a matrix?
Below is some of my data
2018-01-01T00:00 273.450 2.350 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
2018-01-01T01:00 273.250 1.570 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
2018-01-01T02:00 273.350 0.510 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
2018-01-01T03:00 273.250 1.420 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
2018-01-01T04:00 273.350 0.140 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
2018-01-01T05:00 275.550 0.700 -999.000 -999.000 -999.000 -999.000 -999.000 -1.000 -999.000 -999.000 0.000 -999.000 -999.000 -999.000
Thanks!
  댓글 수: 2
Adam
Adam 2019년 1월 15일
What does
whos
show when run on command line? The text of the error message suggests that A does not exist at all rather than anything to do with what type of variable it is.
William Campbell
William Campbell 2019년 1월 15일
whos
Name Size Bytes Class Attributes
A 4x4 128 double
ans 1x4 8 char

댓글을 달려면 로그인하십시오.

채택된 답변

madhan ravi
madhan ravi 2019년 1월 15일
편집: madhan ravi 2019년 1월 15일
EDITED
T=readtable('sample.txt'); % your filename
T(:,[3 4 5 9 10 12 13 14])=[]
Gives:
T =
6×7 table
Var1 Var2 Var6 Var7 Var8 Var11 Var15
__________________ ______ ____ ____ ____ _____ _____
'2018-01-01T00:00' 273.45 -999 -999 -999 -999 -999
'2018-01-01T01:00' 273.25 -999 -999 -999 -999 -999
'2018-01-01T02:00' 273.35 -999 -999 -999 -999 -999
'2018-01-01T03:00' 273.25 -999 -999 -999 -999 -999
'2018-01-01T04:00' 273.35 -999 -999 -999 -999 -999
'2018-01-01T05:00' 275.55 -999 -999 -999 -999 -999
Note: Download the attached document and try my code.
  댓글 수: 12
William Campbell
William Campbell 2019년 1월 15일
Thanks
But there are still " marks around the date?
"2018-01-01T00:00 " 273.45 2.35 -999 -999 -1 0
"2018-01-01T01:00 " 273.25 1.57 -999 -999 -1 0
"2018-01-01T02:00 " 273.35 0.51 -999 -999 -1 0
"2018-01-01T03:00 " 273.25 1.42 -999 -999 -1 0
madhan ravi
madhan ravi 2019년 1월 15일
편집: madhan ravi 2019년 1월 15일
T=readtable('sample.txt'); % your rawdata filename
T(:,[3 4 5 9 10 12 13 14])=[];
T.Var1=datetime(T.Var1,'Format','yyyy-MM-dd''T''mm:ss')
writetable(T,'sample1.txt','Delimiter',' ','WriteVariableNames',0) % I don't see any strings around date

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by