create a function for a cell array

2 vues (au cours des 30 derniers jours)
shobhit mehrotra
shobhit mehrotra le 15 Fév 2015
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

Réponses (1)

Geoff Hayes
Geoff Hayes le 15 Fév 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by