Run a function a few times with always different data? How to?

1 view (last 30 days)
Hi there,
I have the following problem: 1. I read a dataset (no headers or strings) from excel in by xlsread. The first column is a date and the following 5 columns are numerical. The dataset contains 5 rows. With xlsread I get a 5x6 matrix.
2. What I want to do now is to run my function with the data of the first row. Save the solution in a csv file. Then matlab should take the second row of my data, run the function again and save it in the same csv. This routine should be performed until matlab reaches row 5.
3. The csv file should always contain the date, followed by the obtained solution from the function. That must be done for each row.
For simplicity the function could be "func = a+b+c+d+e"
How can I do it?
Thanks in advance boulala

Accepted Answer

Star Strider
Star Strider on 16 Mar 2015
Use a for loop to loop through each row, then save the result as a matrix.
Hypothetical question, so hypothetical solution:
data = xlsread( ... ); % ‘data’ = (5x6) matrix
func = @(vars) var(1) + var(2) + var(3) + var(4) + var(5);
for k1 = 1:5
result(k1,:) = [data(k1,1) func(data(k1,2:6))];
end

More Answers (1)

boulala666
boulala666 on 16 Mar 2015
yeah that works thanks

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!