How can I make different matrices for different values from other matrices?

1 次查看(过去 30 天)
So I have 2 arrays, one containing a bunch of x-coordinates and the other containing a bunch of y-coordinates. They're all in order, such as xco(1,1) is the x-coordinate that pairs with yco(1,1) {Which is the array of y-coordinates}. I would like to pair xco(1,1) and yco(1,1) into a single matrix listing the propper x and y coordinates in a neat display. The issue is the number of x and y coordinates are variable based on user inputs and expressions coded earlier in the program. So for each time a user uses the program the number of x and y coordinates will vary. But I want all the coordinates to show up in one matrix without having to explicitly code them in, which wouldn't work anyways because the number of coordinates vary with each run of the program.
Here is some of the code I've written so far:
for a = 1:holes;
angles = ameasure*a;
A(a)=angles;
end
%Now to find the distance in the x-corrdinate away from the center for each hole
xco = cosd(A)*radius;
%This function represents the distance away from the center in the y-coordinate for each hole
yco = sind(A)*radius;
%Now that we have all the values of each hole calculated, let's put them
%in a more user-friendly display

回答(1 个)

Ishaan Mehta
Ishaan Mehta 2022-6-27
Hi Marvin
I understand that you want to display the values in arrays xco and yco in a neat, user-friendly manner.
This can by done using table datatype in MATLAB.
Here is a code snippet for the same.
% dummy data for xco and yco
xco = randi([1 100], [1 10]);
yco = randi([1 100], [1 10]);
myTable = table(xco', yco'); % create a table with the values of xco and yco
myTable.Properties.VariableNames = ["xco" "yco"]; % rename the columns
myTable
myTable = 10×2 table
xco yco ___ ___ 66 67 45 9 48 46 65 3 21 60 29 80 52 74 56 91 39 63 78 81
Hope it helps
Ishaan Mehta

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by