MATLAB: 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!!

delete valuesMATLAB

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

Best Answer

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)