removevars ERROR for a table

조회 수: 10 (최근 30일)
Karel Starý
Karel Starý 2021년 4월 23일
댓글: Karel Starý 2021년 4월 26일
Hello gusy!
I am starting with new project for my wokr I I got stuck in the beggining.
I am making simple coda in app designer to load a CVS, delete some rows i dont need and then plot a resuts.
Having
Error using tabular/subsasgnParens (line 215)
A table variable subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, or a cell array of character vectors.
Error in tabular/removevars (line 28)
a = move(a).subsasgnParens({':',vars},[],false,true);
[file,path,~] = uigetfile({'.csv'}); % open the dialog box,
% N = file; %create variable with the name of the document
%app.EditField.Value = N; % show document name in text filed
filename = [path file]; %combine path and name
A1= readtimetable(filename); %importing data to parameter AA as a table
%A1.Properties.VariableDescriptions % original names for variables from the logs, before MATLab changed them.
A2 = removevars(A1,{'Lon' 'Lat' 'GPSAltitude_m_' 'GPSTime' 'GPSHead' 'GPSSource' 'GPSDataInd' 'GPSArea' 'LTEKPIPCellServingEARFCN_DL_' ...
'LTEKPIPCellServingEARFCN_UL_' 'LTEKPIPCellServingBandWidthDL' 'LTEKPIPCellServingBandWidthUL' 'LTEKPIPCellPUSCHPowerdBm' 'LTEKPIPCellPUCCHPowerdBm' ...
'LTEKPIPCellSRSPowerdBm' 'LTEKPIPCellTotalTxPowerdBm' 'LTEKPIPCellWBCQICW0' 'LTEKPIPCellWBRI' 'LTEKPIPCellWBRI1Rate' 'LTEKPIPCellWBRI2Rate' ...
'LTEKPIPCellWBRI3Rate' 'LTEKPIPCellWBRI4Rate' 'LTEKPIPCellDLMCS0' 'LTEKPIPCellDLMCS1' 'LTEKPIPCellULMCS' 'LTEKPIPCellDLModulation0' ...
'LTEKPIPCellDLModulation1' 'LTEKPIPCellULModulation' 'LTEKPIPCellPDSCHPRBNumberTB0Including0' 'LTEKPIPCellPDSCHPRBNumberTB1Including0' ...
'LTEKPIPCellPUSCHPRBNumberIncluding0' 'LTEKPIPCellPDSCHBLER' 'LTEKPIPCellPUSCHBLER' 'LTEKPIPCellPUSCHThroughputMbps' 'LTEKPIPCellMACDLThroughputMbps' ...
'LTEKPIPCellMACULThroughputMbps' 'LTEKPIPDSCHPRBNumberAvgTotal' 'LTEKPIPUSCHPRBNumberAvgTotal' 'LTEKPIPDSCHPRBNumberIncluding0Total' ...
'LTEKPIPUSCHPRBNumberIncluding0Total' 'LTEKPIPDSCHBLER' 'LTEKPIPUSCHBLER' 'LTEKPIPDSCHThroughputMbps' 'LTEKPIPUSCHThroughputMbps' ...
'LTEKPIMACDLThroughputMbps' 'LTEKPIMACULThroughputMbps' 'LTEKPIRLCDLThroughputMbps' 'LTEKPIRLCULThroughputMbps' 'LTEKPIPDCPDLThroughputMbps' ...
'LTEKPIPDCPULThroughputMbps' 'LTEKPITAC' 'LTEKPICAType' 'LTEKPIULCAType' 'LTEKPIBandCombination' ...
'QualcommLteLteAdvIntrafreqMeasurePCellNeighborCellNeighborCellC' 'QualcommLteLteAdvIntrafreqMeasurePCellNeighborCellNeighborCellL' ...
'QualcommLteLteAdvIntrafreqMeasurePCellNeighborCellSummaryNeighb' 'QualcommLteLteAdvIntrafreqMeasurePCellNeighborCellNeighborMeasu'});
% delete all shitty collums I dont need
this is the CSV I am working with.
https://drive.google.com/drive/folders/1nCXV5Stf-5oMKg3asAsr2PF0YbLflIs3?usp=sharing
Please be kind and explaing stuff because I might be dumb :D
thanks

채택된 답변

Karel Starý
Karel Starý 2021년 4월 26일
Yeah, it seems like it does not rekognize the name BUT I am positive, its there. Original name for the row is LTEKPIPCellServingBandWidthUL but ater I load the file via readtimetable it change the name to LTEKPIPCellServingEARFCN_DL_. I have try all the possibilities with and withou the "_" , but still no luck (I am using R2021a which should allow the variable name with the spaces, but its not :D ) . I have tryed the approach with patients2 = patients(:, {'LastName', 'Age'}); and there I am stuck with the same issue.
SO MY ISSUE IS THAT MATLAB DOESNT RECOGNIZE MY VARIABLE NAMES CORRECTLY WHEN THERE IS A SPACE IN THE ORIGINAL NAME.
Then I watched some more vids about this and I found out that when i generate a function through the Import Data tool, it looks like this.
SO... If the original name does not contain any "wrong" character (space etc.), it will leave the variable name the same. But if there is a space or something, IT WILL RENAME THE VARIABLE "VarX" where X is the position of variable.
What a beatifull design and no documentation on this under any topic regarding readtable or etc.
Hope this will help someone some day and thanks to both of you guys whom tried to help me.
  댓글 수: 3
Steven Lord
Steven Lord 2021년 4월 26일
Up through release R2019a the variable names in table and timetable arrays were required to be valid MATLAB identifiers using the rules given in the documentation for isvarname (starts with a letter, no more than namelengthmax characters, contains only numbers / letters / underscore, and is not a keyword.) In release R2019b that limitation was removed.
In previous releases, reading the data using readtable should have issued a warning that your variable names had been modified to be valid MATLAB identifiers.
Karel Starý
Karel Starý 2021년 4월 26일
Using R2021A so it should be ok with any string (but its not). Warning is still there but from the table shown in command win. one would say it should just replace spaces with _. But in the end it replace whole name of the variable with VarX as mentioned... I am still a noob, so in the end I believe the problem is sitting on my chair anyway :D. Thanks for all the help guys ...

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

추가 답변 (2개)

Cris LaPierre
Cris LaPierre 2021년 4월 24일
I can't reproduce your error message, but I do get a different error. One of the variable names you are trying to remove does not exist in the file.
Unrecognized table variable name 'LTEKPIPCellServingBandWidthDL'.
a = move(a).subsasgnParens({':',vars},[],false,true);

Steven Lord
Steven Lord 2021년 4월 24일
How many variables does your timetable have and how many do you want to keep? If you only want to keep one or two, rather than removing a lot of variables you could just index and keep the ones you want. For a sample table:
load patients
patients = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
I could remove all the variables except LastName and Age:
patients1 = removevars(patients, {'Gender', 'Height', 'Weight', 'Smoker', 'Systolic', 'Diastolic'});
Or I could keep LastName and Age:
patients2 = patients(:, {'LastName', 'Age'});
Let's check that we received the same results.
areTheyTheSame = isequal(patients1, patients2)
areTheyTheSame = logical
1
We did.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by