Hi Guys
So I have a matrix
a = [16 456 22 85 93;
11 78 310 62 36;
1 66 23 67 405]
how would I add/delete row or column in the matrix? - plot a graph, hold on/hold, turn on grid and label x and y axis?
thank you :)

3 Comments

Jan
Jan on 2 May 2016
What exactly is your question? Adding deleting rows/columns is explained exhaustively in the Getting Started chapters of the documentation. You find descriptions there also about how to plot a graph, the hold command, labels and grids. So do you aks to rephrase the documentation? Simply use the help and doc commands.
Stephen23
Stephen23 on 2 May 2016
Edited: Stephen23 on 2 May 2016
You got links for all of those topics in answer to your earlier question:
Has something changed since you received (and accepted) that answer?
Adding and accessing elements to arrays is a very basic MATLAB usage that you would be better off learning by doing these introductory tutorials:
We are volunteers, not a private tutorial service: the internet has thousand of MATLAB tutorials that will teach you how to to start using MATLAB.
Hi Stephen
Thank you for your reply, I wanted to ensure that the answers are correct and I am going in the right direction

Sign in to comment.

 Accepted Answer

Here you go:
a = [16 456 22 85 93;11 78 310 62 36;1 66 23 67 405];
% Add Row:
a = [a; randi(99, 1, 5)];
% Add Column:
a = [a, randi(99, 4, 1)];
% Delete Row #2:
a(2,:) = [];
% Delete Column #2:
a(:,2) = [];
% Redefine ‘a’:
a = [16 456 22 85 93;11 78 310 62 36;1 66 23 67 405];
x = 1:size(a,2); % Create ‘x’ Variable
figure(1)
plot(x, a(1,:), '-b')
hold on
plot(x, a(2,:), '.-r')
hold off
grid
xlabel('Time (nanoseconds)')
ylabel('Velocity (Furlongs/Fortnight)')

3 Comments

Thank you for taking time to answer this, wanted to ensure that I am using matlab correctly and these answers are great
My pleasure.
When I was in initially learning MATLAB, there were a half dozen of us in the Control Engineering computer lab learning control systems and MATLAB simultaneously. We discovered different things at different times, and helped each other learn both. When it came time to do our own work and not collaborate, we all did well. This was about 17 years before MATLAB Answers began. MATLAB was much smaller then as well, and it was much easier to find information in the documentation (which were all only hardcopy back then, and for the Student Edition, in a single book).
The documentation and materials I have are good, sometimes it just taking another persons view to ensure you're on the right track with answers, can I ask when adding rows/ columns what randi means?

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 2 May 2016

1 vote

Your question is effectively "How do I use MATLAB?"
Rather than explain that here, which might take up a bit of space, let me point you to this tutorial page.

Categories

Find more on Networks 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!