Britt
Britt

Reputation: 21

Loop/Recurse in MatLab

Just started teaching myself MatLab (python background) and I just want to iterate through a simple list of function outputs. I have for example F1 through to F7 as outputs from 7 different functions and I want to put them in a list and return the minimum output value from that list. How would I go about doing this? I know that MatLab uses arrays instead of lists just not sure where to start. Thanks in advance.

Upvotes: 0

Views: 33

Answers (1)

user5756014
user5756014

Reputation: 301

The basic data type of Matlab is matrix which can be any dimensional array. There's no python like list here and you can do the following to achieve what you've asked.

 % Let's say you've value through F1 through F7

 data = [F1 F2 F3 F4 F5 F6 F7];  % creating matrix with the value F1 through F7
 min_value = min(data);
 disp(min_value);

You can do it in Old Fashioned loop structure too.

% Let's say you've value through F1 through F7

 data = [F1 F2 F3 F4 F5 F6 F7];  % creating matrix with the value F1 through 
 F7
 min_value = intmax;
 for i =1:7
    if(min_value > data(i))
       min_value=data(i);
    end
 end
 disp(min_value);

Upvotes: 1

Related Questions