Creating a MATLAB Function File Without Mod/Rem

In summary, the conversation is about creating a MATLAB function file that can accept modulo values from 3 to 9 and output the least possible value that meets the modulo conditions. The speaker is not allowed to use the mod() and rem() functions and is seeking help on how to approach the problem without using arrays, which their professor has prohibited. The suggestion is made to use a counter, do loop, and subtraction to achieve multiplication and division.
  • #1
cpgarcia164
2
0
I need to create a MATLAB function file that will accept a modulo values (from 3 to 9; that is Z3 to Z9) and will output the least possible value describe by the modulo conditions

I don't know how to start it because I am not allowed to use the mod() and rem().

Please give me an idea how to do this, I badly need help with this oneI use array but my prof said it is prohibited because once I use matrix it is easy definable
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
don't quite understand what you are trying to do...it would help if you at least showed the "illegal" way that the prof does not want...but at least we would know what you are trying to achieve...or maybe I am just too ignorant and do not know what Z3 or Z9 is.

Say, can you just use a counter, a do loop and substraction? Multiplication can be achieve by summation and Division by substraction...does this help?
 

What is a MATLAB function file?

A MATLAB function file is a file that contains a set of instructions that perform a specific task or calculation in the MATLAB programming language. It can be called and used in other MATLAB scripts or functions.

How do I create a MATLAB function file?

To create a MATLAB function file, you can use the "function" keyword followed by the name of the function and any input and output arguments. The function body should be enclosed in a pair of parentheses and curly braces.

What is the purpose of creating a MATLAB function file without using "mod/rem"?

The purpose of creating a MATLAB function file without using "mod/rem" is to avoid using these built-in functions, which can be computationally expensive for large datasets. By using alternative methods such as indexing and logical operations, the function can be optimized for faster and more efficient calculations.

Can I use other programming languages in a MATLAB function file?

No, a MATLAB function file is written in the MATLAB programming language and cannot be used to incorporate other programming languages. However, you can use external libraries or functions written in other languages by calling them within the MATLAB function file.

How do I test and debug a MATLAB function file?

You can test and debug a MATLAB function file by running it with different input arguments and checking for errors or unexpected results. You can also use the MATLAB debugger to step through the code and identify any issues. Additionally, using the "disp" function to print out intermediate results can help with debugging.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
20
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
Back
Top