How to put data into a neat table?

1 回表示 (過去 30 日間)
Karan Sandhu
Karan Sandhu 2016 年 3 月 3 日
編集済み: Karan Sandhu 2016 年 3 月 3 日
After a series of frustrating tests, I was finally able to obtain the data needed to form the coordinates given in the picture below. However, I don't know how to actually input my data into MatLab so that it outputs a neat-looking coordinate meshgrid. Some assistance would be nice. Here is my code to generate the data.
x=[-3:3];% all x-values from coordinate table
y=[-4:4]; % all y-values from coordinate table
y=y'; % transpose y
xGrid=repmat(x,[length(y),1]); % makes equal columns of x for rows of y
yGrid=repmat(y,[1,length(x)]); % makes equal rows of y for columns of x
Z= 1.8.^(-1.5*sqrt(xGrid.^2+yGrid.^2)).*cos(0.5*yGrid).*sin(xGrid); % vectorization
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 3 月 3 日
why are you not just calling meshgrid() ?
Karan Sandhu
Karan Sandhu 2016 年 3 月 3 日
Thanks for the reply. Are you saying that I should just use meshgrid(xGrid,yGrid,Z)?

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

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 3 日
Like this:
[xGrid, yGrid] = meshgrid(x,y);
Z= 1.8.^(-1.5*sqrt(xGrid.^2+yGrid.^2)).*cos(0.5*yGrid).*sin(xGrid); % vectorization
% Then print to command window
for kx = 1 : length(x)
thisx = x(kx); % Get this one x.
for ky = 1 : length(y)
thisy = y(ky); % Get this one y
fprintf('(%d, %d, %.4f) ........ you finish it
end
end
  1 件のコメント
Karan Sandhu
Karan Sandhu 2016 年 3 月 3 日
編集済み: Karan Sandhu 2016 年 3 月 3 日
Hi thanks for the reply. In the part where it says "you finish it", my fprintf looks like the following statement below. I'm still not getting this table nor do I understand why I am not getting it. I apologize if the solution to my problem is painfully obvious, but this is my first programming class and I am unfamiliar with MatLab.
fprintf('(%d, %d, %.4f)\n',thisx,thisy,Z)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by