unclear number of if or maybe other commands?!
1 回表示 (過去 30 日間)
古いコメントを表示
Pooneh Shah Malekpoor
2021 年 4 月 21 日
コメント済み: Pooneh Shah Malekpoor
2021 年 4 月 21 日
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 件のコメント
Walter Roberson
2021 年 4 月 21 日
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.
採用された回答
Steven Lord
2021 年 4 月 21 日
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"])
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!