how to write code for 2D image using code for one dimensional plot given below?

a = 0.1;
T = 20;
s = @(x) (2*a*x/T) .* (0<=x & x<=T/2) + (2*a*(1-x/T)) .* (T/2<=x & x<=T);
x = linspace(0, 20);
sv = s(x);
figure(1)
plot(x,sv)
hold on
for k1 = 20:20:60
plot((x+k1),sv)
end
hold off

1 件のコメント

Lipi
Lipi 2017 年 7 月 6 日
編集済み: Lipi 2017 年 7 月 6 日
I understand that your code generates a 2D plot, since you are plotting x [x-axis] verses s(x) [y-axis]. When you say ‘write code for 2D image’; are you trying to form some kind of a 2D pattern using code (given the triangular plot you have generated, it is already a 2D image)? Or are you trying to save the image programmatically? You could directly export the image from the figure window if that is what you are looking for. If you are looking to save a figure in a specific file format using code, it might help to look up the documentation on saving the current figure https://www.mathworks.com/help/matlab/ref/saveas.html .

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

 採用された回答

Star Strider
Star Strider 2017 年 7 月 6 日
I am still not certain what you want.
See if this works:
a = 0.1;
T = 20;
s = @(x) (2*a*x/T) .* (0<=x & x<=T/2) + (2*a*(1-x/T)) .* (T/2<=x & x<=T);
x = linspace(0, 20);
X = repmat(x, 80, 4);
sv = s(X);
figure(1)
imagesc(0:size(X,1)-1, 1:size(X,2), sv)
set(gca, 'YTick',[])

10 件のコメント

ajeet verma
ajeet verma 2017 年 7 月 7 日
編集済み: Star Strider 2017 年 7 月 7 日
sir i want to convert that triangular waveform into triangular fringe pattern, i have an example given below
%sinusoidal wave form
t=0:1/100:1;
f=5;
I=sin(2*pi*f*t);
plot(I);
% sinusoidal fringe pattern
m=1000; % rows
n=1000; % column
f1=20; % No. of vertical fringes
f2=0; % No. of horizontal fringes
for i=1:m
for j=1:n
a(i,j)=sin(2*pi*(f1*j/n+f2*i/m));
end
end
imshow(a,[])
It seems to me that it does. It’s necessary to change the repmat call and change to use imshow, but this seems to do what you want with the triangular waveform that you posted:
a = 0.1;
T = 20;
s = @(x) (2*a*x/T) .* (0<=x & x<=T/2) + (2*a*(1-x/T)) .* (T/2<=x & x<=T);
x = linspace(0, 20);
X = repmat(x, 500, 8);
sv = s(X);
figure(1)
imshow(sv,[])
Note that in the repmat call, the second argument are the number of rows, and the third argument are the number of times the vector repeats horizontally.
ajeet verma
ajeet verma 2017 年 7 月 12 日
i m coding for a circle using for loop, so what's wrong with this code %% circle(2) m=1000; n=1000; for x=1:m; y=1:n; a(x,y)=x^2+y^2<=30; end imshow(a) please correct it
I would define a filled circle as:
a = linspace(0,2*pi,500);
r = 30;
x_circ = r*cos(a);
y_circ = r*sin(a);
figure(1)
fill(x_circ, y_circ, 'r')
axis equal
Experiment to get the result you want, then use the print function to save it in the image format you want.
ajeet verma
ajeet verma 2017 年 7 月 13 日
please check my code and correct it. all details are given in attached file. main problem in my code is second step is not working. code is here: %step-1 %% stair phase clc; clear all; m=1000; n=1000; p=64; N=4; for i= 1:m for j=1:n SP(i,j)=-pi+floor((mod(i-1,p*N)/p))*(2*pi/N-1); end end plot(SP); figure,imshow(SP',[]); %% step-2 % normalize SP1=((SP-min(SP))/(max(SP)-min(SP))); plot(SP1)
ajeet verma
ajeet verma 2017 年 7 月 18 日
編集済み: ajeet verma 2017 年 7 月 18 日
how to write given equation in matlab to find corresponding graph? please see attached file
You are reconstructing a Fourier series. It will not have an infinite number of points.
With all due respect, if you are going to use MATLAB, you need to understand how to code that yourself. Please see the documentation on Getting Started (link).
There are much more efficient ways to code that. However for clarity, I would code it in a for loop. This runs, however I cannot guarantee that it will produce the result you want:
c = ...; % Array Of ‘c’ Values
phi = ...; % Array Of Phase Values
W0 = ...; % Fundamental Frequency
t = ...; % Time Row Vector
x(1,:) = c(1)*ones(1, numel(t));
for n = 2:numel(c)
x(n,:) = 2*abs(c(n))*cos(n*W0*t + phi(n));
end
x = sum(x);
ajeet verma
ajeet verma 2017 年 8 月 2 日
how to increase frequency of the fringes in this code. a = 0.1; T = 20; s = @(x) (2*a*x/T) .* (0<=x & x<=T/2) + (2*a*(1-x/T)) .* (T/2<=x & x<=T); x = linspace(0, 20); X = repmat(x, 1000, 10); sv = s(X); figure(1) imshow(sv,[])
here frequency of fringes is 10, i need around 60 so what parameter is responsible for increasing or decreasing frequency
It is necessary to make a few changes in the code to do what you want.
This should work:
a = 0.1;
Scale = 6; % Repition Number (10 —> 60)
T = 20/Scale;
s = @(x) (2*a*x/T) .* (0<=x & x<=T/2) + (2*a*(1-x/T)) .* (T/2<=x & x<=T);
x = linspace(0, T, T*Scale);
X = repmat(x, 1000, 10*Scale);
sv = s(X);
figure(1)
imshow(sv,[])
ajeet verma
ajeet verma 2017 年 8 月 3 日
i have generated a code for two step phase shifting wave form, code is here: clc; clear all; %TWO STEP PHASE SHIFTING TRIANGULAR TECHNIQUE (WAVE FORM) Imax=0.8; Imin=0.2; Im=Imax-Imin; T = 20; s1= @(x) ((2*Im*x/T)+Imin+Im/2).*(0<=x & x<=T/4) +((-2*Im*x/T)+Imin+3*Im/2).*(T/4<=x & x<=3*T/4)+((2*Im*x/T)+Imin-3*Im/2).*(3*T/4<=x & x<=T); s2= @(x) ((-2*Im*x/T)+Imin+Im/2).*(0<=x & x<=T/4) + ((2*Im*x/T)+Imin-Im/2).*(T/4<=x & x<=3*T/4)+((-2*Im*x/T)+Imin+5*Im/2).*(3*T/4<=x & x<=T); x = linspace(0, 20); X = repmat(x, 1000, 10); I1 = s1(x); I2 = s2(x); figure(1) plot(x,I1,x,I2) it is working but like wise when we generate a code for three step phase shifting code is not working so please help three step phase shifting code is here; clc; clear all; % THREE STEP PHASE SHIFTING TRIANGULAR TECHNIQUE Imax=0.8; Imin=0.2; Im=Imax-Imin; T = 20; s1= @(x) ((2*Im*x/T)+Imin+Im/2).*(0<=x & x<=T/4) +((-2*Im*x/T)+Imin+3*Im/2).*(T/4<=x & x<=3*T/4)+((2*Im*x/T)+Imin-3*Im/2).*(3*T/4<=x & x<=T); s2= @(x) ((2*Im*(x+T/3)/T)+Imin+Im/2).*(0<=(x+T/3) & (x+T/3)<=T/4) + ((-2*Im*(x+T/3)/T)+Imin+3*Im/2).*(T/4<=(x+T/3) & (x+T/3)<=3*T/4)+((2*Im*(x+T/3)/T)+Imin-3*Im/2).*(3*T/4<=(x+T/3) & (x+T/3)<=T); s3= @(x) ((2*Im*(x+2*T/3)/T)+Imin+Im/2).*(0<=(x+2*T/3) & (x+2*T/3)<=T/4) + ((-2*Im*(x+2*T/3)/T)+Imin-Im/2).*(T/4<=(x+2*T/3) & (x+2*T/3)<=3*T/4)+((2*Im*(x+2*T/3)/T)+Imin-3*Im/2).*(3*T/4<=(x+2*T/3) & (x+2*T/3)<=T);
x = linspace(0, 20); X = repmat(x, 1000, 10); I1 = s1(x); I2 = s2(x); I3 = s3(x); figure(1) plot(x,I1,x,I2,x,I3) for more detail please find attachment

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

その他の回答 (1 件)

ajeet verma
ajeet verma 2017 年 8 月 4 日

0 投票

i am trying to create trapezoidal wave form but getting some error i don't know where is wrong please help my code is: %% FIRST TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s1= @(x) (imx+imn).*(0<=x & x<=T/6) +(imx+imn*(2-6*x/T)).*(T/6<=x & x<=T/3)+(imx).*(T/3<=x & x<=2*T/3)+(imx+imn(6*x/T-4)).*(2*T/3<=x & x<=5*T/6); x = linspace(0, 20); I1 = s1(x); figure(1) plot(x,I1) %% SECOND TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s2= @(x) (imx+imn*(6*x/T)).*(0<=x & x<=T/6) +(imx+imn).*(T/6<=x & x<=T/2)+(imx+imn*(4-6*x/T)).*(T/2<=x & x<=2*T/3)+(imx).*(2*T/3<=x & x<=T); x = linspace(0,20); I2 = s2(x); figure(1) plot(x,I2) %% % THIRD TRAPEZOIDAL WAVE FORM clc; clear all; imx=8; imn=2; T = 20; s3= @(x) (imx).*(0<=x & x<=T/3) +(imx+imn*(6*x/T-2)).*(T/3<=x & x<=T/2)+(imx+imn).*(T/2<=x & x<=5*T/6)+(imx+imn(6-6*x/t)).*(5*T/6<=x & x<=T); x = linspace(0,20); I3 = s3(x); figure(1) plot(x,I3) please find attachment

質問済み:

2017 年 7 月 6 日

回答済み:

2017 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by