Index 1 Variable by another

1 次查看(过去 30 天)
Hi there!
I have 2 variables
if true
A = 1
2
NaN
4
end
B= 20
2
5
4
end
I want to remove the '5' from variable B by replacing it with a NaN (i.e. any NaN's in variable A result in a NaN in variable B
I understand this is a simple problem. I have researched but its been a long day Please help x

采纳的回答

Star Strider
Star Strider 2015-4-12
Use ‘logical indexing’:
B(isnan(A)) = NaN
produces:
B =
20
2
NaN
4

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by