Last edited by a moderator: May 5, 2017

  • Thread starter Thread starter nothingatall
  • Start date Start date
  • Tags Tags
    Matlab Max Sum
Click For Summary
SUMMARY

This discussion focuses on implementing two MATLAB functions: maxEntry(A) to find the indices of the maximum entry in an m-by-n matrix and totalSum(A) to calculate the sum of all elements in the matrix. Users are encouraged to avoid built-in functions and utilize array indexing and looping techniques. The importance of understanding MATLAB's array indexing and control structures is emphasized, with references to Mathworks documentation for further guidance.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of array indexing in MATLAB
  • Basic knowledge of loops and control structures in programming
  • Ability to write algorithms and pseudocode
NEXT STEPS
  • Study MATLAB array indexing techniques
  • Learn about MATLAB control structures and looping methods
  • Practice writing pseudocode for algorithms
  • Explore MATLAB documentation on matrix operations
USEFUL FOR

Students learning MATLAB, educators teaching programming concepts, and developers needing to implement custom matrix operations without relying on built-in functions.

nothingatall
Messages
19
Reaction score
0
1) function [p,q] = maxEntry(A)
% A is an m-by-n matrix.
%p and q are indices with the property that |A(p,q)|>=|A(i,j)|
% for all i and j that satisfy 1<=i<=m, 1<=j<=n.

2) function s = totalSum(A)
% A is an m-by-n matrix
% s is the sum of all the values in A

complete them without using built in functions.

3) I've tried to look these up on help but these are not helping. I've tried to create the matrix with an index but this is not working. I think i know how to do a for loop but should i know anything when referring to the function at hand??

Thanks
 
Physics news on Phys.org
These sound like homework, so perhaps a mod will be by to relocate this thread.

Both of these questions are intended to get you familiar with MATLAB's array indexing and looping. If you're not familiar with array indexing, the help documentation is quite helpful:
http://www.mathworks.com/help/techdoc/math/f1-85462.html

Having said that, for at least the summation problem, it's possible to avoid the indexing by using linear indexing instead of (row, column) type indexing. But since you still need it for the first, let's go with that.

Now, as for how to do looping, here's the Mathworks documentation page on various Program Control methods:
http://www.mathworks.com/help/techdoc/matlab_prog/brqy1c1-1.html

If you're new to programming, my advice is to first come up with the algorithm / pseudocode before the specific implementation. Do this here and we'll try to help you along.
 
Last edited by a moderator:

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K