unclear number of if or maybe other commands?!
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Pooneh Shah Malekpoor
il 21 Apr 2021
Commentato: Pooneh Shah Malekpoor
il 21 Apr 2021
Hello
I am confused in writing a code which i am going to explain. imagine there is a row matrix whose dimension is not clear (as in each iteration there may be more arrays in this row vector), e.g. ccc=[10 20 30 40 50 ...]. On the other hand, there is a matrix (called Length(i)) that measures the length of some segments along a curve with respect to an origin. There is a length critteria called:J.
if Length(i)<J then assign ccc1 to that segment
if Length(i)>J or Length(i)<2*J then assign ccc2 to the second segment
if Length(i)>2*J or Length(i)<3*J then assign ccc3 to the third segment
.
.
.
It is worthy to point that Length(i)<J represents segment 1, J<Length(i)<2*J represents segment 2, etc..
it is not clear how many segments and c matrix arrays we would have.. Any recommendation/idea is highly appreciated.
A draft of my code is attached below:
% for i=1:n % n is the number of segments
% Length(i)=sqrt(abs((H(i,1)-PP(1,1))^2+((H(i,3)-PP(1,2))^2)));
%
% if Length(i)<J %for 2 segments,,,what if there are more than 2 segments
%
% C(g,i)= CCC(g,1);
%
% elseif Length(i)>J && Length(i)<2*J
% C(g,i)=CCC(g,2);
%
% end
%
% end
% end
Best Regards
4 Commenti
Walter Roberson
il 21 Apr 2021
In the original form of your question, we could not guarantee that the Length entries were non-negative, so we could not guarantee that ceil(Length / J) would be > 0 . In such a situation then under the definition "if Length(i)<J then assign ccc1" we need to assign the first segment. Rather than testing for negative and using 1 in that case, we can use max(1,value) which will be 1 if value <= 1 and will be the value otherwise.
In the revised form we can see that the Length is a euclidean distance. Euclidean distances can potentially be 0, so we run into the same problem that Length/J might be 0, and ceil(0) is 0. Rather than testing for that case, we can use the max() as before.
Risposta accettata
Steven Lord
il 21 Apr 2021
So you want to discretize your data?
x = rand(10, 1);
binedges = 0:0.25:1;
values = [1.1, 2.22, 3.333, 4.4444];
d = discretize(x, binedges, values);
results = table(x, d, 'VariableNames', ["x", "corresponding values"])
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!