Access to a table, why matlabs run with code: T = T(:,[varnames(others) 'SelfAssessedHealthStatus']); , but later can not run with this one: T(:, ['Systolic' 'Diastolic']) = [];
Show older comments
I have the code below in which 'patients.dat is a sample file in Matlab.
clear all
clc
T = readtable('patients.dat');
T(:, ['Systolic' 'Diastolic']) = [];
varnames = T.Properties.VariableNames;
others = ~strcmp('SelfAssessedHealthStatus', varnames);
T = T(:, [varnames(others) 'SelfAssessedHealthStatus']);
T(1:5,6:7)
When I run this code. Matlab reported an error message:
Error using magic_square (line 5)
Unrecognized variable name 'SystolicDiastolic'.
When I remove line: T(:, ['Systolic' 'Diastolic']) = []; , matlab works well.
My problem is that: the two lines: T = T(:, [varnames(others) 'SelfAssessedHealthStatus']); and T(:, ['Systolic' 'Diastolic']) = []; Have the same syntax, but why matlab reported an error message at the latter (T(:, ['Systolic' 'Diastolic']) = [];)
Can somebody help me explain this phenomenon? many thanks and best regards!
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!