For Loop does not work over a specified Range
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear community,
I try to establish a novel subtable from a datasheet that contains multiple columns I can access by searching two strings.
However, in the final step I have a problem: the for loop I try to run from a specified range (first = column 212, last = column 238) will begin at column 1. The variables between column 1 and 237 will then be stored as zeros. Why is that? And how can I work around it?
Thank you
clearvars ~ data
close all
filepath = ['C:\Hannah\VTA Projekt'];
[~,sheets] = xlsfinfo('Effekte_der_DBS_korrigiert.xlsx');
data = cell(1,numel(sheets));
for s = 1:numel(sheets)
data{s} = readtable('Effekte_der_DBS_korrigiert.xlsx','Sheet',(s));
end
%%
subtable = data{1,3};
T = table2cell(subtable);
str = string(T);
Pattern1 = ('MedOFF_StimON')
getdata1 = endsWith(str,Pattern1);
Pattern2 = ('UPDRS_III')
getdata2 = contains(str,Pattern2);
getdata = getdata1 .* getdata2
[row col] = find(getdata);
first = col(:,1)
last = col(:,end)
for k = 1:row
for j = drange(first:last)
new_table{j} = subtable{:, j}
end
end
0 comentarios
Respuestas (1)
Steven Lord
el 15 de Mayo de 2020
When you execute commands like the following, if myNewVariable didn't exist before the elements in myNewVariable prior to element 7 have to be filled with something. Otherwise you wouldn't be assigning into element 7 of myNewVariable, you'd be assigning into element 1.
For numeric data types, that something is 0. For cell arrays it's {[]}.
myNewVariable(7) = 1
myNewCellArray(7) = {1}
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!