create a function for a cell array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a cell array {data} of indices numbers.
C = {1:23, 24:55, 56:102, 103:255, 256:351} (351 data points)
I have a vector of concentrations of a gas CO2 = 1x351 vector
I want to crate a cell array with the CO2 values evaluated at the indices
CO2E = {CO2(1:23), CO2(24:55), CO2(56:102), CO2(103:255), CO2(256:351)}
I have this so far
for mm = 1:length(C)
dataco2(mm) = (co2(dataind{:,mm}))
end
The end goal is to create a cell array, dataco2 that is the exact same dimension as {C}
Thanks
0 Commenti
Risposte (1)
Geoff Hayes
il 15 Feb 2015
shobhit - you don't say what is wrong with your above code (please do in the future) but if you wish to continue using the loop as above then you should define your CO2E array as a cell array and update it as
CO2E = {};
for mm = 1:length(C)
CO2E{mm} = CO2(C{mm});
end
It is very similar to what you had, though from your above code, it is unclear why you are using dataind instead of C, and co2 instead of CO2.
An alternative to the above is to use arrayfun which we discussed in another post.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!