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 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Cris LaPierre
Cris LaPierre le 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 commentaires
WILLBES BANDA
WILLBES BANDA le 27 Mar 2020
Modifié(e) : Cris LaPierre le 27 Mar 2020
"A" "B" "C" "D" "E"
"23.636245" "3615.6185" "16.355563" "99.827142" "5.6990017e-05"
"20.120486" "2230.758" "20.951501" "60.106325" "5.0372775e-05"
"22.630571" "2826.1319" "16.865655" "66.169075" "8.1334762e-05"
"20.123897" "3884.2918" "22.938844" "90.587924" "6.3031089e-05"
"23.126712" "2465.2629" "22.477316" "63.73416" "4.8937363e-05"
"20.41263" "5260.2423" NoValues "90.316271" "3.1286757e-05"
"19.053762" "2820.8702" NoValues "78.248774" "1.8150422e-05"
"23.279503" "1721.7412" NoValues "94.330213" "8.6873794e-05"
"24.471171" "1269.7014" NoValues "99.036696" "7.0185319e-05"
"22.066035" "2772.7518" NoValues "98.628572" "1.3044774e-05"
This is the script that has the values and its not complete here i just took a small portion, the dimensions are 289x6 in full
Cris LaPierre
Cris LaPierre le 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?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by