I am new in matalb.
5 views (last 30 days)
Show older comments
vibhuti mahant
on 11 Oct 2021
Edited: Walter Roberson
on 12 Oct 2021
- You have been asked to write a function that processes images. An image is represented by a matrix in Matlab. In order to do some processing corner values of the matrix are required. Write a function that returns four outputs for four corners. e.g
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
[TL, TR, BL, BR] = imageCorners(A)
TL = 1, TR = 3, BL = 7, BR = 9
3 Comments
Steven Lord
on 11 Oct 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Accepted Answer
Image Analyst
on 11 Oct 2021
Edited: Image Analyst
on 11 Oct 2021
You can get a value from A by specifying the row and column, like A(row, column). Rows and columns start numbering at 1. The last one is referenced by the shortcut word "end", like A(1, end) or A(end, end), and so on. So use 1 and end in between the parentheses to get the corresponding corners. Of course you'll need all 4 combinations of 1 and end to get all 4 corners.
Use function to define the function
function [TL, TR, BL, BR] = imageCorners(A)
TL = ........
and then when you call it, define A and accept all 4 outputs. So your script would look like:
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
[TL, TR, BL, BR] = imageCorners(A) % Call the function in the main part of the script.
% Define the function below the main part, or in a separate m-file called
% imageCorners.m. If the function is in your test script file, then be
% sure to end your function with the "end" keyword.
function [TL, TR, BL, BR] = imageCorners(A)
TL = ........ You do this part yourself...
end
3 Comments
Image Analyst
on 12 Oct 2021
@vibhuti mahant, yes you do. The variables DO contain the proper values.
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
[TL, TR, BL, BR] = imageCorners(A)
function [TL, TR, BL, BR] = imageCorners(A)
TL= A(1,1);
TR=A(1,end);
BL=A(end,1);
BR=A(end,end);
end
Take the semicolon off the call if you want to see them printed to the command window:
TL =
1
TR =
3
BL =
7
BR =
9
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!