Hi, i am trying to delete NoValue from A without hardcoding so that i am only left with numbers and store them in Absorption vector but when i run the code it comes back exactly as it is, please help!!
1 次查看(过去 30 天)
显示 更早的评论
A = 20.0872
16.1710
20.6179
17.9930
18.6397
16.5852
22.5673
21.0629
19.8378
19.9037
20.2171
21.6581
21.2016
NoValue
NoValue
NoValue
NoValue
NoValue
NoValue
NoValue
NoValue
NoValue
match = 'NoValue';
for Vec = 1:1:length(A)
DeleteValues = strcmp(A,match);
if DeleteValues > 0
newStr = erase(A,match)
Absorption = [newStr]
end
end
0 个评论
采纳的回答
Cris LaPierre
2020-3-27
The conditional of an if statement can only check one value at a time, yet deletedValues is a vector. For your if statement to work in the code you've written, you'd need to check one value at a time doing something like this.
if DeleteValues(Vec)
...
However, you don't need a for loop at all. Take advantage of MATLAB's ability to work with vectors.
A = [20.0872
16.1710
20.6179
17.9930
18.6397
16.5852
22.5673
21.0629
19.8378
19.9037
20.2171
21.6581
21.2016
"NoValue"
"NoValue"
"NoValue"
"NoValue"
"NoValue"
"NoValue"
"NoValue"
"NoValue"
"NoValue"];
z = "NoValue";
DeleteValues = strcmp(A,z);
Absorption = A(~DeleteValues)
6 个评论
Cris LaPierre
2020-3-27
We must be missing something. This script is just a text file of numbers. Running it shouldn't do anything. I actually get an error.
Is there some companion code that somehow captures these values? How do they get used in your script?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!