Managing maximum and minimum values ​​in the elements of an matriz.

2 views (last 30 days)
Hello good afternoon.
I hope you can give me ideas about the solution to this problem that I have.
I have a matrix where the values ​​of the;
first column must be between 2.0 and 2.9
second column must be between 3.0 and 3.9
third column must be between 4.0 and 4.9
fourth column must be between 5.0 and 5.9
fifth column must be between 6.0 and 6.9
A = [2.1 3.0 4.4 5.5 6.1
2.3 3.2 4.2 5.4 6.3
2.1 3.1 4.1 5.2 6.2
2.2 3.1 4.1 5.1 6.6
2.0 3.3 4.3 5.3 6.4];
In case the values ​​are in 0.1 less or more of the limits, that these values ​​are assigned the minimum or maximum values ​​to that element according to the column.
• For example, if I have a value of 1.9 or less in that first column, that value is assigned a value of 2.0 and if it has a value of 3.0 or greater, it will be assigned a value of 2.9
• If in the second column I obtain a value of 2.9 or less, assign it the value of 3.0 and if it has a value of 4.0 or greater, assign it a value of 3.9
and so on to the other columns

Accepted Answer

Rik
Rik on 25 Nov 2019
This should work. The idea is to first find out the base number, adjust the offset if needed, and add the base back.
A = [2.1 3.0 4.4 5.5 6.1
2.3 3.2 4.2 5.4 6.3
2.1 3.1 4.1 5.2 6.2
2.2 3.1 4.1 5.1 6.6
2.0 3.3 4.3 5.3 6.4];
lim=0.1;
base=repmat(1+(1:size(A,2)),size(A,1),1);
dist_to_base=A-base;
dist_to_base(dist_to_base<= lim )=lim;
dist_to_base(dist_to_base>= (1-lim) )=1-lim;
B=base+dist_to_base;

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by