Hi! How I can extract specific data
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone! Kindly ask help in clear data using indexing or other different methods. Appreciate any help
At the end I got this data and I need to write function or code which will take exactly data where the last three column in one row will be >=0 and <=3. My code is above. Please help me, I think I dont have enough knowledge to do it, but I have to do it. I really dont know how to do it. I need to use indexing but dont know how
PPP =
2.0000 1.5000 0 5.3009
4.0000 1.5000 3.0000 0.6991
5.0000 1.5000 3.4558 0
6.0000 1.5000 1.5000 3.0000
clc
clear all
close all
X0 = 1.5;
Y0 = 1.5;
Z0 = 3.0;
Theta0 = 30;
Phi0 = 90;
r = sqrt((X0 - 0)^2 + (Y0 - 0)^2 + (Z0 - 0)^2);
XBar = r * sind(Theta0) * cosd(Phi0) + X0;
YBar = r * sind(Theta0) * sind(Phi0) + Y0;
ZBar = r * cosd(Theta0) - Z0;
ThetaBar = Theta0;
PhiBar = Phi0;
fprintf('XBar: %f\n',XBar);
fprintf('YBar: %f\n',YBar);
fprintf('ZBar: %f\n',ZBar);
planes(:,:,1) = [0 3 3; 0 0 3; 0 3 0; 0 0 0; 0 0 0];
planes(:,:,2) = [0 0 3; 3 0 3; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,3) = [3 0 3; 3 3 3; 3 0 0; 3 3 0; 3 0 0];
planes(:,:,4) = [3 3 3; 0 3 3; 3 3 0; 0 3 0; 0 3 3];
planes(:,:,5) = [0 3 0; 3 3 0; 0 0 0; 3 0 0; 0 0 0];
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
location_plane = 6;
asd=[];
jjj = [];
for j=1:6
j
plane = planes(:,:,j);
p0 = plane(1,:);
p1 = plane(2,:);
p2 = plane(3,:);
p3 = plane(4,:);
V0 = plane(5,:);
Ri = [X0 Y0 Z0];
Rr = [XBar YBar ZBar];
A = p0-p2;
B = p0-p3;
n=cross(A,B); % normal vector of the Plane
u = Rr-Ri;
w=Ri-V0;
D=dot(n,u);
N=-dot(n,w);
sI = N / D;
I = Ri+ sI.*u;
if any(isnan(I))==0 || any(isinf(I))==0
%any(I > 0 & I < 3, "all")
jjj = [jjj j];
asd = [asd; I];
end
fprintf('I: %f\n',I);
X=I(1);
Y=I(2);
Z=I(3);
F = sqrt((X-X0)^2 + (Y-Y0)^2 + (Z-Z0)^2);
fprintf('F: %f\n',F);
fprintf('sI: %f\n',sI);
fprintf('N: %f\n',N);
fprintf('D: %f\n',D);
fprintf('n: %f\n',n);
fprintf('X: %f\n',X);
fprintf('Y: %f\n',Y);
fprintf('Z: %f\n',Z);
p = j;
end
PPP = [jjj' asd]
if X == 0
planes(:,:,1)
ThetaBar = 90-Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
elseif X == 3
planes(:,:,3)
ThetaBar = 90-Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
elseif Y == 0
planes(:,:,2)
ThetaBar = 90 - Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
elseif Y == 3
planes(:,:,4)
ThetaBar = 90-Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
elseif Z == 0
planes(:,:,5)
ThetBar = Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
elseif Z == 3
planes(:,:,6)
ThetaBar = Theta0;
fprintf('I: %f\n',I);
fprintf('plane: %f\n',j);
end
1 Kommentar
Rik
am 28 Feb. 2023
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
Akzeptierte Antwort
Askic V
am 27 Feb. 2023
Hello Aknur,
This example code will perform task you specified.
% code which will take exactly data where the last three
% column in one row will be >=0 and <=3
A = [3 4 5 6 7 8;
1 2 5 3 1 2;
4 6 7 8 3 2;
8 9 1 0 1 2;
4 5 9 9 5 0];
% take last three columns of the matrix
B = A(:,end-2:end)
% number of rows in B
Nr = size(B,1);
% matrix of logical values that satisfy criteria
C = B(1:Nr,:) >= 0 & B(1:Nr,:) <= 3;
% extract only those rows which all elements satisfy criteria
D = B(all(C,2),:)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!