Answered
Error using plot Vectors must be the same lengths.
Use <http://www.mathworks.com/help/matlab/ref/gradient.html |gradient|> instead of |diff|: y2 = gradient(y1);

10 years ago | 1

Answered
Unknow fail using accumarray
You can use <http://www.mathworks.com/help/matlab/ref/unique.html |unique|> to get the required indices: >> A = [0,-1,1,-2,...

10 years ago | 0

Answered
Do you have a suggestion for a name of my function?
Nice idea, sometimes I have needed an efficient tool to do exactly that! Is there any similar inbuilt function? There seems t...

10 years ago | 1

Answered
Maximum value in a vector
The problem is that you don't have a vector, although you think that you do. Actually |y| is a scalar value -1, so of course |mi...

10 years ago | 0

| accepted

Answered
How to reset the size variable inside looping?
Best, most robust and clearest solution: define |area| explicitly not implicitly: area = zeros(totalObject,1); Slowest a...

10 years ago | 0

Answered
Substitute numbers in array
Try this function. The matrix |M| defines any arbitrary values to swap. Note that these values are not used as indices so this i...

10 years ago | 0

Answered
Convert to three dimensional data
How to convert row, column, and page indices into an array: >> M = [1,2,3,10;4,6,9,20;5,4,1,10] M = 1 2 ...

10 years ago | 1

| accepted

Answered
Trim Matrix and find the min-max value the reshaped matrix
Here is how to get the maximum and its indices (change |max| to |min| for the minimum): >> B = [1,7;2,8;3,9] B = ...

10 years ago | 1

Answered
Attempt to grow array along ambiguous dimension.
S1(y3,x3)=2;%pet MATLAB does not accept both |x| and |y| indices together in a vector. These must be entered separately. ...

10 years ago | 1

| accepted

Answered
Error using fwrite Invalid file identifier. Use fopen to generate a valid file identifier.
According to the <http://www.mathworks.com/help/matlab/ref/fopen.html |fopen|> documentation this error occurs _"If fopen cannot...

10 years ago | 1

| accepted

Answered
read and use the ith matrix for the ith determiner
Easy: put the matrices into one cell array. This is a fast and reliable way to program: C = {R1,R2,R3}; % <- one cell array...

10 years ago | 0

| accepted

Answered
what is the difference between pwd and cd ?
Actually |pwd| just calls |cd| internally, so there is no real difference. However I would suggest using |pwd|: Changing dire...

10 years ago | 1

Answered
I do not have the 'Editor' tab available on my Matlab program, is there any way I could display it so I could easily run my code?
This is how a <https://en.wikipedia.org/wiki/Ribbon_(computing) Ribbon> works: the available tabs are context dependent. This me...

10 years ago | 14

| accepted

Answered
How to find dependent column vectors of a matrix for a given column vector?
Guessing a bit because the question is not totally clear... here is a function that returns the column indices of any columns th...

10 years ago | 0

Answered
Error: Subscripted assignment dimension mismatch.
Because |j| is a scalar then |z(j,1)| refers to one element of |z|. There is nothing preventing |newY| from having multiple valu...

10 years ago | 0

| accepted

Answered
constructing matrix with loop
Here is an efficient way of performing that calculation. Note that I did not use any slow, buggy, and awful dynamic variable nam...

10 years ago | 1

| accepted

Answered
How can I rename files with two conditions in a folder?
You can start by reading the <http://www.mathworks.com/help/matlab/ref/movefile.html |movefile|> documentation, which tells us t...

10 years ago | 0

| accepted

Answered
Delete iterations in a string of numbers
Remove repetitions, return a string: >> str = '222223444451111122666677775555533332222'; >> new = str([true,diff(+str)~=...

10 years ago | 1

| accepted

Answered
How to assign several values at once to a field in structure
You need to use <http://www.mathworks.com/help/matlab/ref/deal.html |deal|> or its newer alternative syntax: >> P1= [2 42 2...

10 years ago | 4

| accepted

Answered
Community add-on paid / commercial licensing
Reading the <http://www.mathworks.com/help/matlab/add-ons.html Add-Ons> introduction we find this titbit: _"You can share add-on...

10 years ago | 2

| accepted

Answered
How to replace certain rows in a matrix with the same row vector?
Here is one easy way: new = [0,1,0]; idx = logical(data(:,18)); colours(idx,1) = new(1); colours(idx,2) = new(2); ...

10 years ago | 1

| accepted

Answered
Can I get rid of this for loop?
You cannot get rid of the |for| loop, but you can hide it inside a |cellfun| call. Note that my answer works for any number of c...

10 years ago | 1

| accepted

Answered
Inserting vector to a mxn Matrix
Here is the simple solution without |find|: % preallocate matrix and vector: mat = NaN(3,5); vec = NaN(3,1); % add...

10 years ago | 0

Answered
Design an algorithm and write the program for a machine that must give the current amount of change from rs500 for any amount of change costing less than rs 500. The program must specify the number and all notes and coins as possible. Assume purc
Here is a simple greedy algorithm, based on <http://www.mathworks.com/matlabcentral/answers/30875#answer_39361 Geoff's answer>: ...

10 years ago | 2

| accepted

Answered
indices when the columns are all nan
There is no need to waste time using slow and ugly loops and |if| statements. You can locate those "incorrect" indices very simp...

10 years ago | 2

| accepted

Answered
structfun output array not working
|structfun| is working fine. The problem is how you are using it. Try this: vec = structfun(@numel,timelockdata);

10 years ago | 0

Answered
Error when debugging problem
For no obvious reason you |clear| some variables using this line: clear Value Remainders and then expect to be able to r...

10 years ago | 2

| accepted

Answered
Find the First element that satisfies a condition
No loops or |find| is required, just some logical indexing does the trick: >> A = [7 3 9;5 8 8;0,2,6]; >> B = A.'; % imp...

10 years ago | 1

| accepted

Answered
how to make return value in for loop ?
MATLAB does not need a |return| statement to return a value. To return a value you simply need to list it as an output argument ...

10 years ago | 4

| accepted

Answered
Help please. Error message: statement can't be reached <LINE 42>
The problem is your while loop: while 1 is always true, and you do not have any |break| statement inside the loop. So th...

10 years ago | 0

Load more