What is wrong with [a b] = randi() [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm having trouble with this command
[a b]=randi(5,1,2)
matlab tells me
Too many output arguments.
Can anyone tell me what did I do wrong?

The reason is obvious here as there should be only one output for randi().
r = randi(imax,n)
r = randi(imax,m,n)
r = randi(imax,[m,n])
r = randi(imax,p1,...,pn)
r = randi(imax,[p1,...,pn])
r = randi(imax)
r = randi(imax,size(A))
r = randi([imin,imax],...)
r = randi(..., classname)
Check out its documentation for more info.

As #hero mentioned, you should just get a vector as output of randi.
If you really must get it to different letters, here is how it could be done:
c = num2cell(randi(5,1,2));
[a, b] = deal(c{:});
Needless to say, this is not something you should usually want.

Related

How to define a function with a matrix [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to define a two variables function g so that g(x,y) be a 2*2 matrix. To do this, I define g(x,y)=[1,1;x,y] but when I put g(1,1) I don't get any answer. How can I evaluate to g?
The code g(x,y)=[1,1;x,y] itself will not do anything. I assume that your expect result will be g=[1,1,1,1]? Therefore you should do as follow:
g=g_func(1,1);
disp(g)
function g=g_func(x,y)
g=[1,1;x,y];
end
It's not that different from the previous answer, but perhaps an anonymous function would meet your needs:
>> g = #(x,y)[1,1;x,y];
>> g(5,6)
ans =
1 1
5 6
Alternatively, if you want g to accept only one input (i.e. a 2-element vector, instead of two scalars), you could do:
g = #(x)[1,1;x(1),x(2)];
% or
g = #(x)[1,1;x(:).'];

Whats wrong with this Matlab function [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
function y = CramersRule(A,b)
[m,n] = size(A);
[o,p] = size(b);
if m~=2 | n~=2 | o~=2 | p~=1
error('the matrices must be 2*2 and 2*1')
A=[a b;c d]
b=[e;f]
X = det([e b;f a])/det([a b;c d])
Y = det([a e;c f])/det([a b;c d])
end
end
I just get the result: CramersRule([1 2;3 4], [0;4]), which was an example I used to test it.
There are several strange things here:
First of all you have an if statement that contains an error, but even though there is an error you still do things inside the same statement, perhaps you wanted an else somewhere?
Secondly you use A=[a b;c d] while a, c and d are not even defined.
Thirdly you assign to X and Y which are never even used.
Lastly you ask y as an output argument, whilst there is never an assignment to this. Perhaps you don't realize that matlab is case sensative?
All in all it is just a strange function now. Don't forget to check the mlint (warnings on the right hand side of your screen) as it can pick up most of these things.

access to cell MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
for m=1:numel(myFolder)
end
for x = 1:numel(myFiles) %
for j=1:numel(myFolder)
eachFile{x}{j} = dir(myFiles{x}{j});
end
end
any idea?
This should work
for x = 1:numel(myFiles)
for y = 1:numel(myFiles{x})
eachFile{x}{j} = dir(myFiles{x}{y});
end
end

How can you two color in plot matlab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to make a script to show me a picture like this:
https://www.dropbox.com/s/zzx2chi0jbclf66/Figura.jpg
The code is:
a = load('file.txt');
x = a(:,1);
y = a(:,4);
area(x,y)
But not like making out two colors, I think bruh command is used but not sure?
This submission on the File Exchange might also help:
http://www.mathworks.co.uk/matlabcentral/fileexchange/7255-areashade

Solving a system of equations on Maple [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
solve({4*a = 443*a1/(3.14)+a0, 7*a = 20*a1/(3.14)+a0, 105*a = 543*a1/(3.14)+a0}, {a, a1.a0});
Could someone tell me why MAPLE doens't compute this solution?
It doesn't give anything.
Thank you.
You have a typo. The second argument should be {a, a1, a0} not {a,a1.a0}
solve({4*a = 443*a1/(3.14)+a0, 7*a = 20*a1/(3.14)+a0, 105*a = 543*a1/(3.14)+a0}, {a, a1, a0});