HOW TO SEPARATE NUMERICAL DATA FROM A TEXTFILE?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have to find the median of height ( indicated by the 2nd from last column in the data file i have attached below), at each levels seperately. I have already written a code to find the median which am attaching below. But now i have to seperate them according to their levels ( Levels are indicated by the first column in the data file, which goes like 1,2,3,1,2,3.....) Reading starts from 16th line onwards. The median is found out in such a manner that if the files are placed side by side, we get 4 height datas from a single line/level...like that.....THe result i got from my code looks like this: MEDIAN OF HEIGHT : 500,100,50, 448.05,95.2...In this 500 indicates the median from level1, 100 from level2, 50 from level3. 448.05 from level1, 95.2 from level2.... so on.....IT GOES ON LIKE THIS
So can u please help me modify my code so that i can seperate these median according to their levels. So that output looks likethis : MEDIAN OF HEIGHT AT LEVEL1 :500,448.05...MEDIAN AT LEVEL2: 100,95.2....MEDIAN AT LEVEL3: 50,...
I have tried various methods and none of it works. Iam new to matlab and have very limited programming skills. Pls help
Respuestas (4)
Bjorn Gustavsson
el 22 de En. de 2019
Well you need to find out how many levels you have in your height-arrays, for that I suggest you take a look at the function unique:
helpwin unique
Then you need to determine if you have discrete enough levels to use that function (measurement noise might give you levels varying in a "physically insignifficant" way - this would give you a uselessly large number of levels). If that's the case you'll have to loop over the unique levels and do something like:
for i_levels = numlevels:-1:1,
m_level(i_levels) = mean(variable_of_interest(height==level(i_levels)));
end
If you have measurement noise in your levels then I suggest you look at the file-exchange contribution consolidator
HTH
2 comentarios
Bjorn Gustavsson
el 22 de En. de 2019
Well good for you! Then you can use unique and then my suggested solution, good luck!
HTH
Jeff Miller
el 22 de En. de 2019
mydata = readtable('1Oct6AM.txt','Headerlines',16);
mymedians = CondMedians(mydata,'Var13','Var1')
gives
mymedians =
Var1 Var13_median
____ ____________
1 974.3
2 1005.6
3 1005.4
2 comentarios
lakshmi dwaraka
el 23 de En. de 2019
Editada: lakshmi dwaraka
el 23 de En. de 2019
Thankyou for replaying! But it doesnt solve my question. I have already found out the median. My code is attached there. What i want to do is seperate my median according to the column1 (looks like 1,2,3,1,2,3...)of the file. so that result looks like : median at level1 is 500, 448.05...median at level2 is 100,99.2... median at level3..so on.. These 3 should be 3 seperate files . Hope you understood. Thanks again
Jeff Miller
el 23 de En. de 2019
No, I don't understand. The table mymedians in my answer shows the medians for the 13th column separately for each of the levels 1, 2, and 3 of Var1. Isn't that what you want? I do not understand about "3 separate files"
Jeff Miller
el 23 de En. de 2019
Sorry, I misunderstood completely. Maybe this will do what you want:
level1 = mod(1:507,3)==1;
level1_medians = median_height(level1);
level2 = mod(1:507,3)==2;
level2_medians = median_height(level2);
level3 = mod(1:507,3)==3;
level3_medians = median_height(level3);
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!