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 view (last 30 days)
Show older comments
WILLBES BANDA
on 27 Mar 2020
Edited: Cris LaPierre
on 27 Mar 2020
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 Comments
Accepted Answer
Cris LaPierre
on 27 Mar 2020
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 Comments
Cris LaPierre
on 27 Mar 2020
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?
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!