how to write code for 2D image using code for one dimensional plot given below?
2 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
Star Strider
2017 年 8 月 2 日
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,[])
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!