I need to replace some values with NaN and some values with zeros

1 view (last 30 days)
Hi every one can help
in annexed figure I have table in left handside gives its corresponding curves and I want to replace some values in z1, z2, and z3 to be NaN and replace some values of zb to be zeros by using Matlab If -Condition ro get the right handside that gives the corresponding curves
Thanks in advance
M. Dahab
Arif Hoq
Arif Hoq on 2 Feb 2023
what is the condition?
if gBt >= any value
z1= ????
elseif gBt == any value
z2= ????
Moustafa Abedel Fattah
Moustafa Abedel Fattah on 3 Feb 2023
Can you please use the excel file attached with Voss answer and write the complite code

Sign in to comment.

Answers (1)

Voss on 2 Feb 2023
Edited: Voss on 2 Feb 2023
I've entered the values from your left-hand table into Excel and saved the attached xlsx file.
Read the file into a matrix and plot z1, z2, z3, and zb vs xc:
M = readmatrix('data.xlsx');
Modify the matrix by replacing certain elements with 0 or NaN:
% where gBt is not close to 0.808269 ...
idx = abs(M(:,2) - 0.808269) > 1e-6;
% ... replace z1, z2, z3 with NaN ...
M(idx,3:end-1) = NaN;
% ... and replace zb with 0
M(idx,end) = 0;
Plot again, with new M for comparison:
You can use similar steps on your data.
Moustafa Abedel Fattah
Moustafa Abedel Fattah on 8 Feb 2023
Moved: Voss on 9 Feb 2023
I mean by "swap" as a Matlab order to clean the cell value and then replace with another value if satisfied the condition "if"
thanks for your paying me attention
Voss on 9 Feb 2023
You can substitute "another value" you want to use in place of the NaN in the code above.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!