Answered
Number of times two numbers appear together
>> A = [1,3,2,4,3,4,3,2,1,1,3,2,4,3,3,2]; *Method one: basic indexing and |nnz|:* >> nnz(A(1:end-1)==1 & A(2:end)==2) ...

8 years ago | 0

| accepted

Answered
Unable to perform assignment because the left and right sides have a different number of elements. Error in Assignment6ExcelCodyMadsen (line 44) letter(i) = 'B+' ; How do I fix this problem?
What you are doing will not work: |(i)| refers to *one* element of the char array |letter|, and it is not possible to force mult...

8 years ago | 0

Answered
I want to do a least squares fit to the values around a matrix diagonal including the diagonal itself.
_"How do I query the values in a matrix surrounding the diagonal?"_ <https://www.mathworks.com/help/matlab/ref/diag.html>

8 years ago | 0

Answered
Where am I going wrong in my for loop? I am getting NaNs
The only problem I can see is that you forgot to put the semi-colon on the end of the line. That will display |T_num| on ever...

8 years ago | 0

Answered
Why is MATLAB messing up this very simple calculation.
_"MATLAB calculated the wrong number!"_ Nope, MATLAB calculated the right number. The reason is simply that the value |-2....

8 years ago | 1

| accepted

Answered
(subjectively) IMPORTANT QUESTION! Please help.
_"The problem that I am having is that, I receive an "OUT OF MEMORY" error from MATLAB after going through 3 mice."_ Basicall...

8 years ago | 0

| accepted

Answered
How do I create a filename for TIFF's that change in every loop. Like P01.TIFF then P12.TIFF and so forth. I've set up this in strings but I think the single quotes are missing.
Your code is very verbose for such a simple operation. I recommend using neater <https://www.mathworks.com/help/matlab/ref/sprin...

8 years ago | 0

Answered
Why this error with `axis`
The actual answer is that you _can_ combine multiple inputs, but that those inputs are _not_ name-value inputs (like many other ...

8 years ago | 0

Answered
How to convert cell to double ??
Another guess: str2double @Farman Shah: you have not told us what is _in_ the cell array, so we have no idea what the da...

8 years ago | 0

| accepted

Answered
How to find component of a max value?
Just get the second output from <https://www.mathworks.com/help/matlab/ref/max.html |max|>, which is the index of the maximum va...

8 years ago | 0

| accepted

Answered
Add values to vector
_"I also thought about somehow replacing the 1 in B by values of A"_ You can use logical indexing. Here is an example that wi...

8 years ago | 0

| accepted

Answered
While loop causing an infinite loop in MATLAB
_"Can I get an explanation as to why the code is entering this infinite loop?"_ Of course, it is very simple: you are using a...

8 years ago | 1

| accepted

Answered
How can i write the function which input is a 3×3 matrix, named A, and the program should output corresponding picture in a txt file. The number in matrix A determines how many cubes should be located in the corresponding position.
Here is one approach using simple loops and indexing. You will have to do some fine-tuning to get it to suit your requirement...

8 years ago | 1

| accepted

Answered
Extracting numbers from mixed string
Fully vectorized, one line, and more efficient than |regexp| and/or |str2double|: >> C = {'2001_06m','2001_7m','2001_08'}; ...

8 years ago | 1

Answered
Cumprod for cell arrays?
_"Is this operation possible without for loops?"_ Not really. A loop is the simplest, clearest solution.

8 years ago | 0

Answered
String Input Loop not working
Your code has several bugs. In particular: * Your use of |input| evaluates the input string. MATLAB will assume that the inpu...

8 years ago | 0

Answered
How to set a value range for predefined colormap?
Set the <https://www.mathworks.com/help/matlab/ref/caxis.html |caxis|>: caxis([0,20]) Note that colormaps do NOT have va...

8 years ago | 0

Answered
How can I sort an array with two columns?
Very simply in one line using <https://www.mathworks.com/help/matlab/ref/sortrows.html |sortrows|>: >> Info = [52211,3.55;5...

8 years ago | 0

| accepted

Answered
making loop mat lab
"... but think if you have more then 3000 file how you can run this code" Start by reading the MATLAB documentation: https://w...

8 years ago | 0

| accepted

Answered
User should choose the path for saving variable once
Following the description of <https://www.mathworks.com/help/matlab/ref/uiputfile.html |uiputfile|>, try something like this: ...

8 years ago | 0

| accepted

Answered
How to assume values on an input vector
Use <https://www.mathworks.com/help/matlab/ref/numel.html |numel|> to measure how many elements the input vector has, something ...

8 years ago | 0

| accepted

Answered
populating a cell using a loop
<https://www.mathworks.com/help/matlab/ref/textscan.html |textscan|> returns a 1x55 cell array, where the format string specifi...

8 years ago | 0

| accepted

Answered
How to specifically select columns from a matrix?
>> A = [1,2;3,4;5,6;7,8;9,10] A = 1 2 3 4 5 6 7 8 9 10 >> R = [1,2,3,4,...

8 years ago | 0

| accepted

Answered
difference between e lines of codes
_"...should i use that ./ sign and where i shouldnt use it?"_ You pick the operation based on what operator you need to use. ...

8 years ago | 0

Answered
MALAB gets stuck in finding unlicensedfunctions
<https://www.mathworks.com/matlabcentral/answers/395876-undefined-function-error-is-very-slow-to-occur>

8 years ago | 0

| accepted

Answered
Defining variables inside of a function
t = 0:0.1:2; y = cos(2*t);

8 years ago | 0

Answered
how to load his code
Try something like this: S = dir(fullfile('.','training*')); N = {S([S.isdir]).name}; C = cell(1,numel(N)); for k ...

8 years ago | 0

Answered
How to write matrix to txt or excel file with specific precision
You don't need a loop. Try this: M = your matrix fmt = repmat(',%2.20f',1,size(M,2)); fmt = [fmt(2:end),'\n']; [fi...

8 years ago | 0

| accepted

Answered
Find indices in structure array for structures with field meeting a condition
If the data in the fields can be concatenated together (i.e. have the same number of rows/columns/...) then you could use a <htt...

8 years ago | 1

| accepted

Answered
trying to store data in a matrix using loop
Download my FEX submssion natsortfiles: https://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort ...

8 years ago | 0

Load more