Filling the empty array
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sydney Kehoe
am 7 Jun. 2021
Beantwortet: Star Strider
am 7 Jun. 2021
I am new to matlab and attempting to fill an empty array with data from a for loop using a certain column of data (column f). However, when I try and run the code, it just spit backs out the data from column f and doesn't seem to do anything from the for loop but no errors are shown. Please help.
A = readmatrix('filename');
f = A(:,6);
start_c = [150 278 444 554 612 716];
time_c = [48 42 36 42 42 42];
end_c = [start_c + time_c];
start_dc = [96 214 332 388 496 668];
time_dc = [42 48 42 42 42 36];
end_d = [start_dc + time_dc];
crave = 1;
dcrave = 0;
rest = -1;
empty_array = [];
for ii = 1:length(f)
if f(ii) >= start_c & f(ii) <= end_c
crave;
elseif f(ii) >= start_dc & f(ii) <= end_dc
dcrave;
else f(ii)
rest;
end
empty_array(ii) = f(ii);
end
0 Kommentare
Akzeptierte Antwort
Star Strider
am 7 Jun. 2021
The code does not assign ‘crave’, ‘dcrave’ or ‘rest’ to anything.
What do you want the code to do with those values?
In the interim, perhaps something like:
empty_array = zeros(size(f));
for ii = 1:length(f)
if f(ii) >= start_c & f(ii) <= end_c
empty_array(ii) = crave;
elseif f(ii) >= start_dc & f(ii) <= end_dc
empty_array(ii) = dcrave;
else f(ii)
empty_array(ii) = rest;
end
empty_array(ii) = f(ii);
end
will do what you want.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!