create a function for a cell array
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Geoff Hayes
2015-2-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!