how to copy specific columns of a matrix to a table

10 visualizaciones (últimos 30 días)
Salma fathi
Salma fathi el 28 de Dic. de 2021
Comentada: Sijmen Duineveld el 4 de En. de 2022
I have a matrix of six columns each column for a variable (Altitude, Latitude, Longitude, Azimuth, TEC, Ne). and a table of 3 columns for the vraiables (altitude, Ne and date).the matrix we get it from reading some files. so we have a huge number of files (>1M) we read them into matrices then we check if the latittude and the longitude of a certain chosen row in that matrix are within a certain range then we extract only the columns of the altitude and Ne from the matrix an add them to our table. also each matrix is associated with a certain date so we also need to add the coressponding date to the table. I tried implementing what I want using the following lines but I am not sure if this is a correct implementations since I get no errors but also no output. and I am not sure how I can add the date of a certain matrix to the table with the oethr two colmns. if anyone can help..
attached are two samples of the table and the matrix.
I have modified this code to get rid of of the for loop that may be causing the issue but I am still facing the same problem.
%[Height, Latitude, Longitude, Azimuth, TEC, Ne]
EDPdate= datetime(Year, Month, Day, Hour, Min, 0,'TimeZone','UTC','Format', 'uuuuMMddHHmm');
EDPdate.TimeZone='Asia/Dubai';
EDPT= array2table(EDP);
%(modification is done here) Searching for Profile Peak Parameters' Index
[pks,loc] = findpeaks(EDP(:,6), 'SortStr', 'descend', 'NPeaks', 1);
%Searching for Profile Peak Parameters' Index
%for ied=1:length(EDP)
if EDP(loc,2)>(-13.5) && EDP(loc,2)<(-10.5) && EDP(loc,3)>(-79.8) && EDP(loc,3)<(-73.8)
st = 1;
for ii = 1:length(EDP)
rows = size([tt;EDPT(:,[1,6])],1);%determine the number of rows in tt and EDPT(:,[1,6])
en = st+rows - 1;
tt3(st:en,ii) = [tt;EDPT(:,[1,6])];% assign found values to tt3
st = en +1;
end
end
  1 comentario
Sijmen Duineveld
Sijmen Duineveld el 4 de En. de 2022
First question: are the values [tt;EDPT(:,[1,6])] what you want?
You can simply add an extra line, with only [tt;EDPT(:,[1,6])] (no ";"), so it displays the values in your command window.

Iniciar sesión para comentar.

Respuestas (1)

Sargondjani
Sargondjani el 28 de Dic. de 2021
It is not clear what format EDPT has. And also the variable tt3 will be assigned a different value during each loop. If you want store all values tt2 and EDPT(:,[1,6]) during your loop you need to do something like:
st = 1;
for ii = 1:i_lng
rows = size([tt2;EDPT(:,[1,6])],1);%determine the number of rows in tt2 and EDPT(:,[1,6])
en = st+rows - 1;
tt3(st:en,ii) = [tt2;EDPT(:,[1,6])];% assign found values to tt3
st = en +1;
end
This code is highly inefficient, but lets first try to get your code running. Once it runs you can work on efficiency if speed matters, and for example use concentenate (function cat)
  4 comentarios
Salma fathi
Salma fathi el 29 de Dic. de 2021
this loop is for finding the index of what we call the peak of a profile, which is the max value between the values that has Altitude > 190. but i don't understand, whatever I am trying to do is being executed after this loop finishes all its iterations, so shouldn't it not affect whatever is executed next. please correct me if I am wrong and how e may fix that?
Sargondjani
Sargondjani el 29 de Dic. de 2021
Ok, so you have the location of the maximum value in column 6 which is 'loc'.
And then you check if the point is within a certain range of longitude and latitude:
if EDP(loc,2)>(-13.5) && EDP(loc,2)<(-10.5) && EDP(loc,3)>(-79.8) && EDP(loc,3)<(-73.8)
You should first check if this condition is ever true, because there has to be a peak which is within this range:
So after the 'if statement, put a line:
if EDP(loc,2)>(-13.5) && EDP(loc,2)<(-10.5) && EDP(loc,3)>(-79.8) && EDP(loc,3)<(-73.8)
display('If statement is passed. Lets have a look what happens next')
tt
EDPT(:,[1,6])]
%put a breakpoint here by right clicking in the left margin
end
Run the code, and see if this gives you what you expect. The variables tt and EDPT(:,[1,6])] are now displayed on screen.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by