I have written a script that is supposed to do some calculations on a .csv-file that the user has chosen, and write the results to different columns in an .xlsx-file.
I have a loop that runs through different letters for a variable that decides which column in the .xlsx should have the written data – this works. The part that doesn't is the loop with an array, rfd200left(k), that calculates a number on 5 different columns in the .csv-file. What I get in the columns of the .xlsx is the same number on all 5 cells (I get the last calculated number of the loop. I tried moving around almost everything, but I can't find the flaw. The code is below, and the .csv-file is attached for context. Let me know if any additional information is needed.
This first part is a browse-button, that let's the user browse for a csv-file to be read.
function vaelgPushed(app, event) %Browse files
[filename, pathname] = uigetfile('*.csv'); app.UIFigure.Visible = 'off'; app.UIFigure.Visible = 'on'; app.fullpathname = strcat(pathname, filename); app.valgt.Value = app.fullpathname; % Read csv-file
app.rfdtest = csvread(app.fullpathname, 8, 1);end
The next part is the button that analyzes the csv-file, and writes calculated data to an excel-document. This is where my loop is doing something wrong at the "writetable"-part:
function analyserPushed(app, event)rfdtest = app.rfdtest; fullpathname = app.fullpathname;threshold = 1.5;newton = 4.44822162;for k = 1 : 5 left = rfdtest(:, k); if left(1)>0 left=[0;left] % If the first item in a column is not zero, add zero.
end for letter='E':'I' column = [letter,'2'] % Variables for calculations
indexoverLeft = find(left>threshold,1);P1Left = left(indexoverLeft,1); prethreshLeft = indexoverLeft-1;P2Left = left(prethreshLeft+21);% -- Find RFD 200 ms [Pounds/sek]
if (P2Left-P1Left)/0.2 > 0 rfd200left(k) = (P2Left-P1Left)/0.2; T = table(rfd200left(k)); writetable(T,'rfd_skitse_kopi.xlsx', 'range', column, 'WriteVariableNames', false) end endendend
Best Answer