Overwrite table data with 'Yes' or 'No' according to the logical index
Mostra commenti meno recenti
Hello everybody,
I would like to overwrite the table data if the logical index of row is true.
Logical index will be True if sampleinput.TEST_ITEM1 is'TV'
In case of True, the sampleinput.TEST_LOAD1 need to be changed with 'Yes'.
and False, the sampleinput.TEST_LOAD1 need to be changed with 'No'.
Please give me some help.
load sample1
idx = sampleinput.TEST_ITEM1 == "TV";
sampleinput.TEST_LOAD1(idx) = 'Yes';
idx = sampleinput.TEST_ITEM1 ~= "TV";
sampleinput.TEST_LOAD1(idx) = 'No';

Risposta accettata
Più risposte (1)
Simpler:
S = load('sample1.mat');
T = S.sampleinput
X = strcmpi(T.TEST_ITEM1,'TV');
T.TEST_LOAD1(:) = {'No'};
T.TEST_LOAD1(X) = {'Yes'}
2 Commenti
Smithy
il 2 Set 2022
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!