array processing and sorting
8 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone, I have a big problem for my matlab skill level
One of my measuring instruments generates and exports an array like the one below (normally 100+ rows x 5-20 colums) in which each column is in ascending order. Further complication is that often in the last rows there are zeros because in case of different column lengths, a zero-filling process is automatically executed
a =
1 1 1
2 3 2
3 3 4
5 5 7
6 9 9
13 10 15
0 0 20
0 0 25
Now if the standard deviation of each row is <=1 then the entire row should be transcribed into a new array, else if standard deviation are >1 the row elements must be split into one or more new lines so that they remain overall anyway ascending sorted. I hope I explained. It is difficult for me to explain even in my language.
In other words I had to get this result
b =
1 1 1
2 3 2
3 3 4
5 5 0
6 0 0
0 0 7
0 9 9
0 10 0
13 0 0
0 0 15
0 0 20
0 0 25
I will have to import this array into another instrument that can also accept NaN instead of filling with zeros.
thank you in advance
Davide
0 件のコメント
採用された回答
Image Analyst
2023 年 6 月 26 日
This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own, but here's a start:
a = [
1 1 1
2 3 2
3 3 4
5 5 7
6 9 9
13 10 15
0 0 20
0 0 25];
[rows, columns] = size(a)
sd = std(a, 0, 2)
b = zeros(rows, columns);
for row = 1 : rows
if sd(row) < 1
% SD less than 1 so simply transfer the entire row.
b(row, :) = a(row, :);
else
% SD more than 1. TO DO: Split into separate rows.
end
end
b
3 件のコメント
Image Analyst
2023 年 6 月 26 日
OK, no problem (75% of people here are students). However, I am not clear on how you want to split up a row with stdev>1 into two or three rows. And I'm not sure how the zeros are to be handled. In the code I gave, of course the zeros are included in the formula for stdev. Do you not want them to be?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

