create a function for a cell array
조회 수: 1 (최근 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!