# Matlab storing data and checking conditions

• thestrong
In summary, the goal of this function is to find all of the values in a list that satisfy a set of conditions.
thestrong

## Homework Statement

clear all;
close all;
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 calculationhere is a true statement to see if conditions are met

if (true == 1)
flag = 1;
break;

## 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.

ok, you need to clearly explain what the GOAL of this function is. after that we can help you with a solution.

clear all;
close all;
k=21;
flag =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
notlisted=isequal(s,B);
if (notlisted == 1)
break;
end;
end;
flag = 1;
break;
end
end
end
end
end
end
endBasically 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.

## 1. How do I store data in Matlab?

In Matlab, data can be stored in variables using the assignment operator "=", for example: x = 5 would store the value 5 in the variable x. Arrays can also be used to store multiple data values in a single variable.

## 2. What are the different data types in Matlab?

Some common data types in Matlab include numeric (e.g. integers, decimals), character (e.g. strings), logical (e.g. true/false), and cell (e.g. containers for different data types). There are also data structures such as arrays and structures that can hold multiple data values.

## 3. How can I check conditions in Matlab?

Matlab has several conditional statements, such as if/else and switch/case, that can be used to check conditions and execute different code based on the outcome. These statements typically use logical operators (e.g. == for equal to, && for logical AND) to evaluate conditions.

## 4. Can I store data from a file in Matlab?

Yes, Matlab has built-in functions for importing data from various file types, such as csvread for comma-separated values and xlsread for Excel files. These functions can be used to store the data in variables that can then be manipulated and analyzed in Matlab.

## 5. How can I save my data in Matlab for future use?

You can use the save function in Matlab to save your data in a .mat file, which is a binary file format that can be read by Matlab. This allows you to easily load your data back into Matlab at a later time without having to re-enter it. You can also use other file formats, such as .csv or .txt, to save your data in a more human-readable format.

• Engineering and Comp Sci Homework Help
Replies
8
Views
1K
• Engineering and Comp Sci Homework Help
Replies
1
Views
1K
• Engineering and Comp Sci Homework Help
Replies
10
Views
2K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K
• Engineering and Comp Sci Homework Help
Replies
7
Views
2K
• Engineering and Comp Sci Homework Help
Replies
3
Views
2K
• Engineering and Comp Sci Homework Help
Replies
1
Views
2K
• Calculus and Beyond Homework Help
Replies
3
Views
660
• Engineering and Comp Sci Homework Help
Replies
1
Views
9K
• Engineering and Comp Sci Homework Help
Replies
1
Views
2K