|
INTERVIEW QUESTIONS
MULTIMEDIA
MATLAB
DETAILS
Question: Can MATLAB pass by reference?
Answer: This is really two questions in one. One is "Can I modify a function's input argument?" This would save memory and simplify
programming in some cases. The answer here is "NO". If you modify the input argument of a function, all you do is modify a
copy of the argument local to the function. The only way to modify variables from a function is to return the result when
finished, as in
bigstruct = addelement(bigstruct, 5);
The other question is: "Pass by value wastes memory and time, since copies of variables are made. How can I fix this?" Here,
the answer is "Your assumption is flawed, you don't need to." MATLAB uses a scheme called "copy-on-write" to optimize this
sort of thing. Basically, data is shared between variables whenever possible, and a true copy is made only when one of the
variables is modified. So although MATLAB's calling convention appears to be pass-by-value, if you don't modify the input
variables, the data is never copied.
|
|
|
Category |
Matlab Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9046 users |
Added on |
9/2/2014 |
Views |
69480 |
Rate it! |
|
|
Question:
Can MATLAB pass by reference?
Answer:
This is really two questions in one. One is "Can I modify a function's input argument?" This would save memory and simplify
programming in some cases. The answer here is "NO". If you modify the input argument of a function, all you do is modify a
copy of the argument local to the function. The only way to modify variables from a function is to return the result when
finished, as in
bigstruct = addelement(bigstruct, 5);
The other question is: "Pass by value wastes memory and time, since copies of variables are made. How can I fix this?" Here,
the answer is "Your assumption is flawed, you don't need to." MATLAB uses a scheme called "copy-on-write" to optimize this
sort of thing. Basically, data is shared between variables whenever possible, and a true copy is made only when one of the
variables is modified. So although MATLAB's calling convention appears to be pass-by-value, if you don't modify the input
variables, the data is never copied. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How to modify the MATLAB path?
|
View Answer
|
|
How to save default settings across sessions?
|
View Answer
|
|
How can I make MATLAB use the full window width for displaying matrices?
|
View Answer
|
|
Why does MATLAB only calculate to 4 significant digits?
|
View Answer
|
|
What is the FAQ editorial policy?
|
View Answer
|
|
Where can I find an archive of comp.soft-sys.matlab?
|
View Answer
|
|
What is MATLAB?
|
View Answer
|
|
Explain about stress analysis in Matlab?
|
View Answer
|
|
How to call matlab in batch mode?
|
View Answer
|
|
How to correctly apply the graphics patches in Matlab?
|
View Answer
|
|
Can we run Matlab without graphics?
|
View Answer
|
|
Explain LaTeX in Matlab?
|
View Answer
|
|
On what machines Matlab should be run?
|
View Answer
|
|
Vectorization What is that in Matlab? How to do it ?
|
View Answer
|
|
What can we use Matlab for?
|
View Answer
|
|
how to Add noise to an image in Matlab?
|
View Answer
|
|
Explain The MATLAB Application Program Interface (API)?
|
View Answer
|
|
Explain The MATLAB mathematical function library?
|
View Answer
|
|
Explain Handle Graphics in Matlab?
|
View Answer
|
|
Explain The MATLAB working environment?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Matlab Interview Questions & Answers - Exam Mode /
Learning Mode
|