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

 Akzeptierte Antwort

Image Analyst
Image Analyst am 26 Jun. 2023

0 Stimmen

DId you try std and a for loop?
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)
rows = 8
columns = 3
sd = std(a, 0, 2)
sd = 8×1
0 0.5774 0.5774 1.1547 1.7321 2.5166 11.5470 14.4338
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
b = 8×3
1 1 1 2 3 2 3 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3 Kommentare

Davide Bertelli
Davide Bertelli am 26 Jun. 2023
I’m sorry you misunderstood, this is not a homework assignment. Unfortunately, I’m too old to be a student. I am an associate professor in chemistry at the University of Modena and Reggio Emilia in Italy. This is my personal e-mail davide.bertelli@unimore.it and here you can find my CV (http://personale.unimore.it/rubrica/dettaglio/bertelli). I usually use Matlab for statistical purpose but in this case I have to transport the results from an instrument to another incompatible one and my skills on array transformation are very very basic.
Best regards
Davide
Image Analyst
Image Analyst am 26 Jun. 2023
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?
Davide Bertelli
Davide Bertelli am 29 Jun. 2023
It’s hard for me to explain it, in trying to do so I insert an image that I hope can clarify the result I need.
I am realizing that the problem is very difficult to solve, because I have a high number of columns and there may be different values that increase SD, and this would require a split in many rows.
Considering that my values are all integer, I thought that a more convenient solution might be to use some fill gaps function with 0 or NaN on each column and then delete all rows which contain only zero.
i.e.
Thank you for help, sorry for my silly questions.
Davide

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by