How can i write the function which input is a 3ร3 matrix, named A, and the program should output corresponding picture in a txt file. The number in matrix A determines how many cubes should be located in the corresponding position.
mathworks.com โบ matlabcentral โบ answers โบ 422733-how-can-i-write-the-function-which-input-is-a-3x3-matrix-named-a-and-the-program-should-output-cor
Here is one approach using simple loops and indexing.
You will have to do some fine-tuning to get it to suit your requirements.
A = [0,0,0;0,2,1;0,1,0]; % Input 3x3 matrix.
%
M = [... % base cube
'~~~______~';
'~~/ /|';
'~/ / |';
'/_____/ |';
'| | /';
'| | /~';
'|_____|/~~'];
%
Sa = size(A);
Sm = size(M);
Xm = M~='~';
Xr = cell(Sa);
Xc = cell(Sa);
% Generate indices:
for ii = 1:Sa(1) % back -> front.
for jj = 1:Sa(2) % left -> right.
for kk = 1:A(ii,jj) % bottom -> top.
R = ii*3 - kk*3;
C = jj*6 - ii*3 - kk; % try without kk.
Xr{ii,jj} = [Xr{ii,jj};R+1-Sm(1):R];
Xc{ii,jj} = [Xc{ii,jj};C+1-Sm(2):C];
end
end
end
% Normalize indices:
Xr = vertcat(Xr{:});
Xc = vertcat(Xc{:});
Xr = 1+Xr-min(Xr(:));
Xc = 1+Xc-min(Xc(:));
% Place cube at required locations:
Z = repmat(' ',max(Xr(:)),max(Xc(:)));
for nn = 1:sum(A(:))
tmp = Z(Xr(nn,:),Xc(nn,:));
tmp(Xm) = M(Xm); % keep char outside the cube.
Z(Xr(nn,:),Xc(nn,:)) = tmp;
end
disp(Z)
Displays this in the command window:
______
/ /|
/ / |
/_____/ |______
| | / /|
| | / / |
|______/_____/ |
/ /| | /
/ / | | /
/_____/ |_____|/
| | /
| | /
|_____|/
Tested with the first example input matrix:
>> A = [0,0,0;0,1,1;0,0,0]
A =
0 0 0
0 1 1
0 0 0
Giving
____________
/ / /|
/ / / |
/_____/_____/ |
| | | /
| | | /
|_____|_____|/ Answer from Stephen23 on mathworks.com
MathWorks
mathworks.com โบ aerospace blockset โบ standard workflow procedures โบ coordinate systems โบ math operations
Create 3x3 Matrix - Create 3-by-3 matrix from nine input values - Simulink
The Create 3x3 Matrix block creates a 3-by-3 matrix from nine input values where each input corresponds to an element of the matrix.
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 403928-how-to-make-a-3x3-matrix
How to make a 3x3 matrix - MATLAB Answers - MATLAB Central
June 4, 2018 - Open in MATLAB Online ยท Hello every one; I want to make a 3x3 general matrix using three different function as shown in code. It is working but I want to know how to save the results in three different lines of same matrix. Also how to run this matrix in command window for some defined value of theta.
13:12
Basic Operations with Matrices in Matlab - YouTube
06:38
How to Solve System of Equations in MatLAB - 2x2 and 3x3 - YouTube
03:12
MATLAB Help & Tutorials - Eigenvalues for a 3x3 Matrix by Electrical ...
11:27
How to Creating Matrices in MATLAB | MATLAB Tutorial 3 - YouTube
31:03
Working with Matrices in Matlab - YouTube
05:42
Matlab Tutorial - Multiplying Matrices - YouTube
MathWorks
mathworks.com โบ matlab โบ mathematics โบ linear algebra
Basic Matrix Operations - MATLAB & Simulink Example
MATLAB has many applications beyond just matrix computation. To convolve two vectors ... ... At any time, we can get a listing of the variables we have stored in memory using the who or whos command. ... Name Size Bytes Class Attributes A 3x3 72 double B 3x3 72 double C 3x3 72 double a 1x9 72 double ans 3x1 24 double b 3x1 24 double p 1x4 32 double q 1x7 56 double r 1x10 80 double x 3x1 24 double
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 285210-define-a-matrix-3x3-using-matlab
Define a Matrix 3x3 using matlab - MATLAB Answers - MATLAB Central
May 20, 2016 - I'm tryin to define a 3x3 matrix using matlab but I get an error: Undefined function or variable 'A'. Here's my code: J := matrix([[-(l1+q2)*sind(q1)-l3*sind(q1+q2), cosd(q1), -l3*sind(q1+q3)...
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 481257-how-to-turn-assigned-vectors-into-a-3x3-matrix
How to turn assigned vectors into a 3x3 matrix? - MATLAB Answers - MATLAB Central
September 20, 2019 - If your vec3 is not a typo, then you have too many elements in vec3 to make it part of the 3x3 matrix. ... https://www.mathworks.com/matlabcentral/answers/481257-how-to-turn-assigned-vectors-into-a-3x3-matrix#comment_747930
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 1855773-how-to-make-a-3x3-matrix-a-9x1-matrix
how to make a 3x3 matrix a 9x1 matrix? - MATLAB Answers - MATLAB Central
November 18, 2022 - Further, you can know this, if you understand how the elements are stored in MATLAB matrices. A matrix in MATLAB stores the elements going down each column, one at a time. Since reshape does not change the order of the elements in a matrix, then you need to do that FIRST.
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 272653-loop-to-create-3x3-matrix-for-each-frame
loop to create 3x3 matrix for each frame - MATLAB Answers - MATLAB Central
March 10, 2016 - Hi I want to build a 3x3 Matrix from 3 vectors. R.fcsR = [Xn.fcsR; Yn.fcsR; Zn.fcsR]; I have captured a movement of a point over 247 frames. How can I make a for loop, so that for every ...
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 397470-how-to-generate-all-the-3-by-3-matrices
How to generate all the 3 by 3 matrices ? - MATLAB Answers - MATLAB Central
April 26, 2018 - You want to create all 16 billion of them. Each matrix is a 3x3 matrix. In the form of a double, that will take up 9*8=72 bytes to store. So the entires set of roughly 16 billion matrices will require something like 1152 gigabytes of memory to store.
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 266106-how-do-i-divide-a-3x3-matrix-in-three-vertical-or-horizontal-one-dimensional-vectors-using-a-functio
How do I divide a 3X3 matrix in three vertical or horizontal one-dimensional vectors using a FUNCTION? - MATLAB Answers - MATLAB Central
February 1, 2016 - Just wanted to know how do I create a function which accepts a 3X3 matrix and returns three declared arrays from the vectors elements in the rows and columns. Can anyone help? (MATLAB beginner btw)
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 501303-3x3-matrix-with-while-loop
3x3 matrix with while loop - MATLAB Answers - MATLAB Central
January 21, 2020 - Produce a random 3x3 matrix A that is invertible and display it. Hint: Use a while-loop until you get one with non-zero determinant. To create a random matrix with N rows and M columns,use the MATLAB command rand(N,M).
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 496929-how-to-run-a-3x3-matrix-through-a-for-loop-and-save-all-instances-of-the-3x3
how to run a 3x3 matrix through a for loop and save all instances of the [3x3] - MATLAB Answers - MATLAB Central
December 18, 2019 - This returns a 300x1 cell for y. This 300x1 cell contains 300 3x300 doubles but I am trying to get 300 3x1 doubles. So I think I am very close to my final output, it may be an error in my matrix multiplication, thank you for your help and insight. ... https://www.mathworks.com/matlabcentral/answers/496929-how-to-run-a-3x3-matrix-through-a-for-loop-and-save-all-instances-of-the-3x3#comment_779012
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 497739-how-to-create-a-matrix-3-3-from-1-to-9-by-using-for-loop
how to create a matrix (3*3) from 1 to 9 by using for loop - MATLAB Answers - MATLAB Central
December 22, 2019 - How to create a matrix (3*3) from 1 to 9 by using For loop like: 1 2 3 4 5 6 7 8 9 ................. for i=1:3 %row% for j=1:3 %column% a(i,j)= input('a='); end end...
MathWorks
mathworks.com โบ matlabcentral โบ answers โบ 1750690-how-to-store-multiple-iterations-of-a-3x3-matrix-using-a-for-loop
How to store multiple iterations of a 3x3 matrix using a for loop. - MATLAB Answers - MATLAB Central
June 29, 2022 - Below is a piece of my foor loop that I have created to generate Cpp_p_extrap (accoridng to rules not included in this). My goal is to create and store n iterations of the "Cpp_p_extrap" matrix. Im...