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

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

2 件のコメント

Arif Hoq
Arif Hoq 2023 年 2 月 2 日
what is the condition?
if gBt >= any value
z1= ????
elseif gBt == any value
z2= ????
end
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2023 年 2 月 3 日
Can you please use the excel file attached with Voss answer and write the complite code

サインインしてコメントする。

回答 (1 件)

Voss
Voss 2023 年 2 月 2 日
編集済み: Voss 2023 年 2 月 2 日
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');
figure();
plot(M(:,1),M(:,3:end))
set(gca(),'YDir','reverse');
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:
figure();
plot(M(:,1),M(:,3:end))
set(gca(),'YDir','reverse');
You can use similar steps on your data.

8 件のコメント

Moustafa Abedel Fattah
Moustafa Abedel Fattah 2023 年 2 月 3 日
Thanks it is good and work and hope another answer with using if-condition
If you must use an if condition:
M = readmatrix('data.xlsx');
figure();
plot(M(:,1),M(:,3:end))
set(gca(),'YDir','reverse');
for ii = 1:size(M,1)
if abs(M(ii,2) - 0.808269) > 1e-6
% where gBt is not close to 0.808269
% replace z1, z2, z3 with NaN ...
M(ii,3:end-1) = NaN;
% ... and replace zb with 0
M(ii,end) = 0;
end
end
figure();
plot(M(:,1),M(:,3:end))
set(gca(),'YDir','reverse');
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2023 年 2 月 3 日
Thanks very much and appreciet your effort for helping me
it work exactly as I want in
Voss
Voss 2023 年 2 月 3 日
You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2023 年 2 月 6 日
移動済み: Voss 2023 年 2 月 6 日
Dear
I don't know if I would be annoying if I asked for a solution to the problem using If.....and......Swap. Thanks in advance.
Voss
Voss 2023 年 2 月 6 日
What do you mean by "Swap"? I've showed a solution using "if", in a comment above.
Moustafa Abedel Fattah
Moustafa Abedel Fattah 2023 年 2 月 8 日
移動済み: Voss 2023 年 2 月 9 日
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
Voss 2023 年 2 月 9 日
You can substitute "another value" you want to use in place of the NaN in the code above.

サインインしてコメントする。

質問済み:

2023 年 2 月 2 日

コメント済み:

2023 年 2 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by