1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab storing data and checking conditions

  1. May 13, 2015 #1
    1. The problem statement, all variables and given/known data
    clear all;
    close all;
    totalanswers=zeros(100,4);
    k= ;
    flag =0;
    for i =0:25
    a=i;
    if flag ==1
    break;
    end

    and so forth for a,b,c,d, etc for a finite set of values all have the break values too.

    x=[ a,b,c,d];

    does some math calculation


    here is a true statement to see if conditions are met

    if (true == 1)
    answers=[a,b,c,d]
    if (answers ~=[previous ones])
    flag = 1;
    break;




    3. The attempt at a solution

    I need a way to store all the set of variables [a,b,c,d] that satisfy the conditions in totalanswers and to continue to run after one has been found.
     
  2. jcsd
  3. May 15, 2015 #2

    donpacino

    User Avatar
    Gold Member

    ok, you need to clearly explain what the GOAL of this function is. after that we can help you with a solution.
     
  4. May 29, 2015 #3
    clear all;
    close all;
    k=21;
    flag =0;
    allanswers=zeros(100,5);

    while(allanswers(21,:) ~= [0,0,0,0,0])

    %need to add a for loop and flags for each variabled added
    for i =0:20
    a=i;
    if flag ==1
    break;
    end
    for j=0:20
    b=j;
    if flag == 1
    break;
    end
    for h =0:20
    c= h;
    if flag == 1
    break;
    end
    for l=0:20
    d=l;
    if flag ==1
    break;
    end
    for p=0:20
    e=p;
    %need to add variables when changing k
    x=[a,b,c,d,e];

    [Xcols, Xrows] = meshgrid(x, x);
    G = Xcols-Xrows;
    G = G.';
    G(logical(eye(size(G)))) = [];
    G=mod(G,k);
    S=sort(G);

    AllElements = zeros(1,k-1);
    count = 1;
    for i=1:k-1
    AllElements(i) = count;
    count = count+1;
    end

    true=isequal(S,AllElements);
    if (true == 1)
    %need to add variables when changing k
    s=[a,b,c,d,e];
    s=sort(s);
    for i = 1:k
    B=allanswers(i,:);
    notlisted=isequal(s,B);
    if (notlisted == 1)
    allanswers(i,:)=s;
    break;
    end;
    end;
    flag = 1;
    break;
    end
    end
    end
    end
    end
    end
    end


    Basically I want the code to store all of the values into all answers and run until at least 21 "answers" are found instead of doing it manually. I am not sure what would be an effective method to run until 21 [a,b,c,d,e] answers that satisfy the module conditions I set.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab storing data and checking conditions
Loading...