-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.m
More file actions
53 lines (41 loc) · 1.32 KB
/
print.m
File metadata and controls
53 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
clc; clear all; close all;
% Load data (computed previously with Runge-Kutta 4)
Q = readmatrix('./q.csv'); % Array of linearly spaced charges
y = readmatrix('./y.csv'); % Array of corresponding final vertical positions
% Plot the final vertical position vs charge
figure
plot(Q,y)
ylim([-6e-4,6e-4])
ylabel("Final vertical position (m)")
xlim([Q(1),Q(end)])
xlabel("Ink droplet charge (C)")
title("Vertical Position vs Charge")
% get RGB array and dimensions
[colors, width, height] = imgToMatrix('image.png');
ylin=linspace(4,-4,height);
xlin=linspace(0,10,width);
[x1, y1]=meshgrid(xlin,ylin);
qimp = zeros(size(x1));
ximp = reshape(x1.',1,[]);
yimp = reshape(y1.',1,[]);
yimp=yimp*1e-4; % Adjust the size
ycoords = zeros(1,size(ximp,2));
for i=1:size(yimp,2)
j=find(((yimp(1,i)-3e-5)<y)&(y<(yimp(1,i)+3e-5)));
j = j(round((1+size(j,2))/2)); % use midpoint
qimp(i)=Q(j);
ycoords(i)=y(j);
end
disp("Matrix of charges saved to 'charges.csv'.") % This is what a real printer might need
writematrix(qimp,'charges.csv')
% Print
disp("Printing...")
ximp(2,:) = NaN; % Add row of NaNs
ycoords(2,:) = NaN; % ADd row of NaNs
figure
colororder(colors) % Set the color of the ink droplets
plot(ximp, ycoords,'.','MarkerSize', 18);
title('Print')
xticks([])
yticks([])
xlim([0, 10])