Question

Write a code that plots the rows of a matrix (rows) one by one. after plotting...

Write a code that plots the rows of a matrix (rows) one by one. after plotting eah vector, if you clicked the plot with the mouse it should store that row (array) in a new matrix. [MATLAB}

0 0
Add a comment Improve this question Transcribed image text
Answer #1


function plotMatrixAndCopyClicks(M)
% M = original matrix, newMatrix = new matrix

rows = numel(M(:,1));
cols = numel(M(1,:));
newMatrix = [];

figure
axes('NextPlot', 'add') % keep adding the next plots on the figure
k = 1;
h = plot(M(k,:),'-','LineWidth',2, 'color',rand(1,3)); % plotting the 1st row of the original matrix while saving the handles in h
set(h,'ButtonDownFcn',{@selectedPlot,h}) % getting the click event


%% function to respond to clicks
function selectedPlot(objH,~,~)
set(objH, 'LineStyle','--'); % change the line style of clicked line to --
data = get(objH,'ydata'); % retrieve data of the selected line
newMatrix(k,1:cols) = data; % store the data retrieved to new matrix
disp('New Matrix: ')
disp(newMatrix);
save('newMatrix.mat','newMatrix') % save the new matrix


k = k+1;
if k<=rows
h = plot(M(k,:),'-','LineWidth',2, 'color',rand(1,3)); % plot the rest of the rows after every click until all the rows of M are exhausted
end
set(h,'ButtonDownFcn',{@selectedPlot,h}) % getting the click event recursively
end

end


7 6 5 4 3 1 3.5 4.5 1 1.5 2 2.5 3 4. 5 LO C

Command Window Figure 1 [2,3,4,5,6.. > M= Help Window Desktop Tools Insert Edit View File 1,2,3,4,7. .. 4,1,3,6,5 м - 7 4 3 2

------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
Write a code that plots the rows of a matrix (rows) one by one. after plotting...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a code that plots columns in a matrix one by one. while plotting, the code...

    write a code that plots columns in a matrix one by one. while plotting, the code should allow 2 seconds to see each column plotted before moving to the other one. During those 2 seconds the user should have the ability to print the plotted vector by clicking it?

  • cope the code please thanks Write a MATLAB code to obtain the following. Keep your code...

    cope the code please thanks Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Generate a matrix "A" as follow. A= 16 6 8 2 10 18 12 14 4 I. II. Divide the matrix A by 2 and store the result in a matrix B. Combine matrices A & B to obtain the following matrix C. Also...

  • Write a code that gets the quiz grades of a class. A matrix with n rows...

    Write a code that gets the quiz grades of a class. A matrix with n rows and m columns where n stands for number of students and m is the number of quizzes. Let’s call the matrix A. Then, your code drops the lowest grade of each student and remove it from the matrix. Also, it finds the average grade for the quizzes for each student and add a new column to the end the matrix. in matlab please

  • 1. Write a MATLAB function that takes a matrix, a row number and a scalar as...

    1. Write a MATLAB function that takes a matrix, a row number and a scalar as arguments and multiplies each element of the row of the matrix by the scalar returning the updated matrix. 2. Write a MATLAB function that takes a matrix, two row numbers and a scalar as arguments and returns a matrix with a linear combination of the rows. For example, if the rows passed to the function were i and j and the scalar was m,...

  • MATLAB code help!! Homework 3 - Arrays, Masking, Systems of Equations, Plotting, and Numerical Methods Function Name: s...

    MATLAB code help!! Homework 3 - Arrays, Masking, Systems of Equations, Plotting, and Numerical Methods Function Name: sysEq Inputs: 1. (double) An NxN array representing an A matrix 2. (double) An Nx1 vector representing a b matrix Outputs: 1. (double) An Nx1 vector representing the resulting x matrix Background: Whoo, who woulda thunk it? Actually useful things in MATLAB? You bet! This method of solving systems of linear equations is useful in a wide variety of places, from solving mesh...

  • 3. Write a script that adds rows to the database that you created in exercise 2....

    3. Write a script that adds rows to the database that you created in exercise 2. Add two rows to the Users and Products tables. Add three rows to the Downloads table: one row for user 1 and product 2; one row for user 2 and product 1; and one row for user 2 and product 2. Use the SYSDATE function to insert the current date into the download_date column. Use the sequences created in the previous exercise to get...

  • what is a good matlab code to out put this matrix from question 1 to 3...

    what is a good matlab code to out put this matrix from question 1 to 3 HITA 1)-The general form cf the quadratic equation is a +bx+c 0 Wrte a MATLAB function named quadratic that finds the two roots of this equation and x when given the coeficients a, b and c 2)-Create a random matrix A in MATLAB with 6 rows and 3 oolumns using the rand) function 3)-Now modify quadratic by so that il can take each row...

  • Assume that y is a column vector with ten elements, write matlab code that will create...

    Assume that y is a column vector with ten elements, write matlab code that will create a stem plot of the vector starting at a horizontal axis value of 1. Add code that will create the stem plot of the vector starting at a horizontal axis value of 0. Create additional code that creates a stem plot but plots y at every other horizontal value (i.e., 0, 2, 4, etc)

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • MATLAB scripts are how multiple lines of code can be executed vs. entering in a line...

    MATLAB scripts are how multiple lines of code can be executed vs. entering in a line of code one at a time through the command window. Write a script that does the following. Only display to the console window what is specified. Creates a 4 x 10 matrix with the 1strow being 1 to 10, the 2ndrow being 11 to 20, the 3rdrow being 21 to 30, and the last row being 31 to 40. The matrix is shown on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT