Input real image of solar system into matlab

Hi guys,
How can we put real image of solar system: planets, sun into matlab? I have tried to research but no luck. I tried to input galaxy image into my code it keeps saying file is not found and if i put in a different tab it allows me to. That will be great if anyone could help. Thank you.

댓글 수: 7

[filename, pathname] = uigetfile('*.*', 'Select an image file');
fullname = fullfile(pathname, filename);
img = imread(fullname);
imshow(img)
Jack Nguyen
Jack Nguyen 2019년 5월 4일
편집: Image Analyst 2019년 5월 4일
Thanks for your response Walter. I'm still new to matlab and tried it but it did not work. Could you please elaborate it a little bit more? For example I'm trying to input a real image of the earth into the solar system that I'm working on with image file name : 'galaxy.jpg', path to it is : C:\Users\jj\Desktop . How would I do that with the image and the path above? Thank you very very much in advance. (I have tried to searched for days but no luck yet)
This is my code:
% Initialise variables to hold the physical constants
clear;
clc;
% Set a vector for mass
mass = [1.989e30; 0.33011e24; 4.8675e24; 5.9723e24; 0.64171e24; 1898.19e24; 568.34e24; 86.813e24; 102.413e24]; %kg
deltaT = 432000;
G= 6.67e-11; %N*m^2*kg^-2
% Set position vector for planets
p = [0 0 0 ; 5.8e10 0 0; 1.08e11 0 0; 1.5e11 0 0; 2.28e11 0 0; 7.78e11 0 0; 1.427e12 0 0; 2.871e12 0 0; 4.498e12 0 0];
%
% Set velocity vector 'v'
v = [0 0 0; 0 47.36e3 0; 0 35.02e3 0; 0 29.78e3, 0; 0 24.07e3 0; 0 13.06e3 0; 0 9.68e3 0; 0 6.80e3 0; 0 5.43e3 0];
% % Open a figure for plotting and set up the axes
% image_file = 'galaxy.jpg';
% R = importdata(image_file);
% image(R)
% imwrite(image, 'galaxy.jpg')
plot3 (p(1,1),p(1,2),p(1,3),'yo','linewidth',7);
hold on
h2 = plot3(p(2,1), p(2,2), p(2,3), 'bo','linewidth',2);
h3 = plot3(p(3,1), p(3,2), p(3,3), 'yo','linewidth',2.5);
h4 = plot3(p(4,1), p(4,2), p(4,3), 'bo','linewidth',2.2);
h5 = plot3(p(5,1), p(5,2), p(5,3), 'ro','linewidth',2);
h6 = plot3(p(6,1), p(6,2), p(6,3), 'yo','linewidth',5);
h7 = plot3(p(7,1), p(7,2), p(7,3), 'yo','linewidth',3);
h8 = plot3(p(8,1), p(8,2), p(8,3), 'co','linewidth',3);
h9 = plot3(p(9,1), p(9,2), p(9,3), 'bo','linewidth',3);
A2 = animatedline;
A3 = animatedline;
A4 = animatedline;
A5 = animatedline;
A6 = animatedline;
A7 = animatedline;
A8 = animatedline;
A9 = animatedline;
% Set Axes limit
% xlim([-2e11 2e12 ]);
% ylim([-2e11 2e12]);
% zlim([-2e11 2e11]);
%% Iterate each element in mass, p and v
while true
for i = 2:1:numel(mass)
F = zeros(numel(mass),3);
a = zeros(numel(mass),3);
for j= 1:1:numel(mass)
if i~=j
r = p(j,:,:) - p(i,:,:);
F(j,:) = G* mass(i)* mass(j) .* r/((norm(r).^3));
end
end
%% Updating new acceleration, velocity and position for each planet
a(i,:) = sum(F)/ mass(i);
v(i,:) = v(i,:) + a(i,:) *deltaT;
p(i,:) = p(i,:) + v(i,:) .* deltaT;
%
end
%%
% Updating new acceleration, velocity and position for each planet
% Set xdata, ydata, zdata
set(h2, 'XData',p(2,1), 'YData',p(2,2),'ZData',p(2,3));
set(h3, 'XData',p(3,1), 'YData',p(3,2),'ZData',p(3,3));
set(h4, 'XData',p(4,1), 'YData',p(4,2),'ZData',p(4,3));
set(h5, 'XData',p(5,1), 'YData',p(5,2),'ZData',p(5,3));
set(h6, 'XData',p(6,1), 'YData',p(6,2),'ZData',p(6,3));
set(h7, 'XData',p(7,1), 'YData',p(7,2),'ZData',p(7,3));
set(h8, 'XData',p(8,1), 'YData',p(8,2),'ZData',p(8,3));
set(h9, 'XData',p(9,1), 'YData',p(9,2),'ZData',p(9,3));
%%
% Draw animated lines
addpoints(A2, p(2,1),p(2,2));
addpoints(A3, p(3,1),p(3,2));
addpoints(A4, p(4,1),p(4,2));
addpoints(A5, p(5,1),p(5,2));
addpoints(A6, p(6,1),p(6,2));
addpoints(A7, p(7,1),p(7,2));
addpoints(A8, p(8,1),p(8,2));
addpoints(A9, p(9,1),p(9,2));
drawnow limitrate;
end
I don't see imread() in your code. Please attach 'galaxy.jpg' so we can fix the code.
filename = 'C:\users\jj\Desktop\galaxy.jpg';
R = imread(filename);
image(R)
Using imread() instead of importdata()
I'm trying to use this image for the back ground. My plot is 3D and this only 2D image so should I have to convert it into 3D somehow? I'm not sure how to convert it by the way. When I import this image to my plot it only show the image not the actual solar system.
Technically, I'm not sure how to start. I'm intend to put the image of the actual earth, sun, venus, and other planets so make it more realistic. I should looks something like this the image below. Capture.PNG
What would you recommend, please? Thank you!
galaxy.jpg
Do you want a static background image that should always appear "behind" the plot no matter what is drawn in front of it? Do you want it to be like a single piece of paper behind the plot, that the user would view at different angles if they were to rotate the plot? Were you hoping for proportionally sized and positioned spheroids that would get larger or smaller and more or less detailed according to angle and how close the user zoomed? Does the user need to be able to zoom into the ice mountains of Pluto and into license plates on Earth?
If there is a way to make the background 3D that would be great. I dont think I will need proportionally sized and postion spheroids that would get larger or smaller according to angle at this stage. I'm still a beginner and hoping to learn once I learn other stuff first. And I don't need to see ice mountains of Pluto or other details. Just what it looks like the picture of solar system above will be a bounus to me. Would you please kindly walk me through as I have been researched for days but no luck yet not like I just want to know straight away without doing research. Thank you so much!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기

태그

질문:

2019년 5월 4일

댓글:

2019년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by