create empty row inside a vector
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi. I need to analyze the rows of the vector 'value_GS_test' and transform only the numbers 254 and 255 (if any) into '[]' while keeping the same number of rows as in the original vector. Here is an example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1436613/image.png)
Right now I am using this code, but it only deletes one row (at 255) for me. How can I get the desired result?
value_GS = importdata("value_GS_test.mat"); % 6 elements
for rows_value_GS = 1 %:height(value_GS)
analysis_number = value_GS(rows_value_GS);
if analysis_number == 255
value_GS(rows_value_GS) = [];
elseif analysis_number == 254
value_GS(rows_value_GS) = [];
else
value_GS(rows_value_GS) = value_GS(rows_value_GS);
end
end
5 Commenti
Simon Chan
il 18 Lug 2023
What is the final purpose of making a bracket to those positions? For display only? Or you will write it as blank on a text file?
Risposta accettata
Chunru
il 18 Lug 2023
load(websave("value_GS_test.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1436593/value_GS_test.mat"));
value_GS = double(value_GS)
value_GS(value_GS>=254) = nan;
value_GS
7 Commenti
Dyuman Joshi
il 18 Lug 2023
Yes, it is.
When you try to assign NaN (or Inf for that matter) to a uint8 (or any integer data type) array, it will display 0 instead of NaN
%Signed integer data type example -
y = int16(1:4)
%Assinging 2nd element of the vector to be NaN
y(2) = NaN
%Unsigned integer data type example -
%Initializing NaN with an unsigned integer leads to 0 as well
z = uint8([1 23 NaN 19 5])
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!