How to attribute vectors from a matrix some proprieties?
8 views (last 30 days)
Show older comments
I have to create a matrix with 4 columns and with some proprieties.The first column is a ,second b , third c , forth d.Those numbers have to be in an interval ( 1 ,2 ,...,10000) and the conditions are : a>b , (a-c)(b-d)>0, c>d.I've tried to "attach" to a vector a condition that depends on another vector , but i failed,I have to create a matrxi with There are a few rules before creating that matrix:
- You can't use while.
- You can't use for.
- In 1 matrix must appear all of the combinations that verifiy the conditions below.
Does someone know how to apply proprieties to a vector or have any idea how to resolve this problem ? I've tried a few methods but all of them failed.
4 Comments
Accepted Answer
Luna
on 12 Jan 2019
Hello Victor,
You can try below code. Please read my comments. I hope it helps.
n = 4;
a = randi(10000,n,1); % creates random a from 1-10000 with n rows
b = arrayfun(@(x) randi(x,1,1),a); % creates random b with n rows. Each element in b is smaller than a's corresponding element (for each row)
% (a-c)(b-d) > 0 means a>c and b>d at the same time. So the following c and d created by this rule
c = arrayfun(@(x) randi(x,1,1),a); % creates random c with n rows. Each element in c is smaller than a's corresponding element (for each row).
d = arrayfun(@(x) randi(x,1,1),b); % creates random d with n rows. Each element in d is smaller than b's corresponding element (for each row).
T = [a,b,c,d]; % your nx4 matrix
%% checks if the below condition is OK for each row.
% if proof is 1, all rows fit the condition.
%If proof is zero at least one row in T does not fit the condition.
proof = any((a-c).*(b-d) > 0);
3 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation 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!