Iron Edge

Iron Edge => Off Topic Discussion => Topic started by: Starbrow on April 13, 2012, 01:49:40 pm

Title: Dat code. Help plx?
Post by: Starbrow on April 13, 2012, 01:49:40 pm
Right, so I'm trying to code a clever way of getting some of my research plotted. What I've got is a bunch of lists that could look like this:

parameter_one = [180; 180; 180; 200; 180; 200; 200; 180];
parameter_two = [200; 261.8; 157.1; 130.9; 78.5; 157.1; 261.8; 392.7];
result_example = [50 40 45 43 52 63 53 57];
result_deviation = [1 2 1 2 1 2 1 2];

Now, I want to plot the results as a function of parameter two, but in sets that are separated by parameter one i.e. first plot all the results that have parameter one set to 180, then plot all the results that have parameter one set to 200 (see sketch). My problem is that I can't seem to find a very effective way of splitting up these lists in a way where I don't hard code the number of unique values of parameter one or two.

Edit: This is in MATLAB, if this matters. I can handle plotting the deviation myself, so don't worry about that.
Title: Re: Dat code. Help plx?
Post by: Gaeios(Graxlos) on April 13, 2012, 01:57:06 pm
Ok Im not at all sure I understans what you want but it seems you want a loop for all unique values of parameter one, as outer loop.
then for each you want a loop with all the values of the given number right?
Title: Re: Dat code. Help plx?
Post by: Starbrow on April 13, 2012, 02:08:57 pm
Right, I guess the lines are actually a bit misleading. I'll try a better drawing:
Title: Re: Dat code. Help plx?
Post by: Gaeios(Graxlos) on April 13, 2012, 02:47:29 pm
make a number of arrays based on amount of unique values. take the y values from the corresponding places in the result array.
then plot the new arrays.
Title: Re: Dat code. Help plx?
Post by: Starbrow on April 13, 2012, 05:27:26 pm
My eventual solution (temperatures is the same as parameter_one, res_times is parameter_two, while full_FWHM is results):

% The unique temperatures are found and sorted after size
b = unique(temperatures);
% Finds the number of different temperatures used
c = size(b,1);
map = colormap(jet(c)); % Creates c different colours on the jet scale
i = 1; % Running integer needed in the if-loop
k = 1; % Running integer needed in the while-loop
% Loop then plots the points
while k < size(res_times,1)+1
    % First, we figure out which temperature index the point to be plotted
    % corresponds to
    eval_temp = temperatures(k);
    if eval_temp == b(i)
        % If the temperature is equal to the i'th unique value in the
        % temperature array, the point is plotted using the i'th color in
        % the colorlist map
        p = plot(res_times(k),full_FWHM(k),'o','MarkerFaceColor',...
            map(i,:),'MarkerSize',6,'MarkerEdgeColor','k');
        % The next few lines are merely to make sure the point is removed from the
        % legend
        hAnnotation = get(p,'Annotation');
        hLegendEntry = get(hAnnotation,'LegendInformation');
        set(hLegendEntry,'IconDisplayStyle','off')
        % Since we have found a match, we need to reset the index and
        % increase the loop value by one
        i = 1;
        k = k+1;
    else
        % If the temperature evaluated is not equal to the i'th unique
        % temperature, the index i is increased by one, and we try again
        i = i+1;
    end
end