How can I replace values that meet a condition when I work with matrices and structures?

When efSin09(ch,tt) is equal to 0, xcoord_noOverlap{tt*3-2,1}(ch,:) should become NaN. Here efSin09 is 142x16 double, xcoord_noOverlap is 48x3 cell where each cell has a different amount of rows and colums, tt = [1:16] and ch is the amount of rows for every cell of xcoord_noOverlap and therefore changes for every loop of tt but is always a positive number without decimals. I tried to do this with an if-statement, that didn't give an error, but for some reason was just ignored by Matlab. The error I get now is "Error: File: PostProcessNetwork_ver09_JoyceC.m Line: 1831 Column: 9 ()-indexing must appear last in an index expression.".
if true
% for tt = 1:NumTimesteps
for ch = 1:size(xcoord_noOverlap{tt*3-2,1},1)
xcoord_noOverlap{tt*3-2,1}(ch,:)(efSin09(ch,tt) ~= 1) = NaN;
end
end
end

 Accepted Answer

Based on just your first sentence, this is what you are trying to do:
for tt = 1:NumTimesteps
for ch = 1:size(efSin09,1)
if (efSin09(ch,tt) ~= 1)
xcoord_noOverlap{tt*3-2,1}(ch,:) = NaN;
end
end
end
However, you lost me at the next sentence. In particular: "ch is the amount of rows for every cell of xcoord_noOverlap and therefore changes for every loop of tt."
If the code above doesn't do what you are trying to do, can you please clarify your question a little?

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!