array processing and sorting
조회 수: 2 (최근 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!