"for" cycle to plot the point in a matrix with a certain radius

조회 수: 6 (최근 30일)
javarocket
javarocket 2023년 3월 24일
댓글: javarocket 2023년 3월 24일
Hi everyone,
I have a compressor blade defined in polar-cylindrical coordinates and I would like to write a script that plot just the points located at a certain radius (that will correspond to the hub or to the shroud of the blade).
I tried to use the code below, but it did not work.
Does anyone could help me?
Thank you very much
clear all
close all
clc
data = importdata("blade_pol.mat")
radius = data(:,1)
x = data(:,3);
y = data(:,1).*data(:,2);
for k = 1:size(data,1)
if radius(k,1) == 0.1160
plot(x(k),y(k))
end
end

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 3월 24일
You should use tolerance to compare floating point numbers. Set tolerance according to the level of precision you want.
And use hold on command to retain all the points on the same plot, otherwise your plot will be over-written.
for k = 1:size(data,1)
if abs(radius(k,1) - 0.1160)<1e-4 %tolerance
plot(x(k),y(k))
hold on
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by