How do I create a new matrix based on elements from a previous matrix?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix with columns depth and year. I have a vector, depth2, that is basically depth but with a few random rows missing. I would like an output that shows me what years correspond to the depths present in depth2.
depth=[1 2 3 4 5 6 7 8]
year=[2007 1960 1915 1871 1828 1785 1735 1680]
depth2=[3 4 5 7 8]
ideally year2 would be [1915 1871 1828 1735 1680]
The full depth/year matrix is size 149:2.
0 Commenti
Risposta accettata
ANKUR KUMAR
il 1 Ott 2018
Modificato: ANKUR KUMAR
il 1 Ott 2018
depth=[1 2 3 4 5 6 7 8]
year=[2007 1960 1915 1871 1828 1785 1735 1680]
depth2=[3 4 5 7 8]
year2=arrayfun(@(x) year(depth==x),depth2)
If the previous prog seems to be difficult for you, then you can use simply loop.
depth=[1 2 3 4 5 6 7 8]
year=[2007 1960 1915 1871 1828 1785 1735 1680]
depth2=[3 4 5 7 8]
for i =1:length(depth2)
index=find(depth==depth2(i));
year2(i)=year(index)
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!