PLOTING DATA INTO GRAPHICS
1 view (last 30 days)
Show older comments
EXECUTE THE RESULTS OF NUMBER, MATRIX, VECTOR OPERATIONS AND CONVERT THEM INTO GRAPHICS?
form book: Menke, W., 2024, Geophysical Data Analysis and Inverse Theory, Academic Press.
3 Comments
DGM
on 28 Aug 2024
Edited: DGM
on 28 Aug 2024
There is no specific question. If you want to practice, just start practicing.
% some matrices
A = [1 0 2; 0 1 0; 2 0 1];
B = [1 0 -1; 0 2 0; 1 0 3];
C = [2 0 1; 0 3 0; 3 0 4];
% some column vectors
a = [1; 3; 5];
b = [2; 4; 6];
% basic matrix arithmetic
S = A + B
D = A - B
P = A * B
% various notes from the body text
% the text emphasizes that these aren't generally equivalent
% but the book gives a poor example since A = A' in this case
Q1 = A'*B
Q2 = A*B
% multiplication is not commutative
% these should differ
P1 = A*B
P2 = B*A
% multiplication is associative
% these should be the same
P3 = (A*B)*C
P4 = A*(B*C)
% multiplication is distributive
% these should be the same
P5 = A*(B+C)
P6 = A*B + A*C
% the transpose of a product
% these should be the same
P7 = (A*B)'
P8 = B'*A'
% equivalent forms of the inner product
% these should be the same
s1 = a'*b
s2 = b'*a
% sum of squares (squared length)
sl = a'*a
% the outer product
os = a*b'
% this is a literal character vector
myfilename = 'mydata.txt'
% programmatically generate character vectors
k = 1;
myfilename = sprintf('myfile_%03d.txt',k) % use leading zeros
d = 10.40;
mysentence = sprintf('distance d is %.2f football fields',d)
% get some data from somewhere
tbl = readmatrix('TemperatureData.csv','range','C1:D32');
day = tbl(:,1);
temp = tbl(:,2);
% and make a graph
hold on
set(gca,'linewidth',2,'fontsize',12)
plot(day,temp,'r-','linewidth',2);
plot(day,temp,'ko','linewidth',2);
xlabel('Day')
ylabel('Temperature (\circ F)')
title('Temperature for January 2015')
... and so on. I'm surprised I typed that much before I got bored. I'm assuming you don't actually need dlmwrite().
If you want to go over basics, see MATLAB Onramp:
If you don't have a copy of MATLAB, you should be able to use MATLAB Online on a time-limited basis per month for free.
Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!