Answered
howto multiline error msg
It is written quite clearly in the <https://www.mathworks.com/help/matlab/ref/error.html |error|> help that to throw _"...a form...

10 years ago | 4

Answered
Translate matlab code for syntax maple in matlab
Why do you need Maple for this? What is wrong with MATLAB code, e.g. John D'Errico's excellent FEX submission <http://www.mathwo...

10 years ago | 2

| accepted

Answered
How to find the location of approximately equal value in vector?
You should calculate the absolute differences, and then use |min| to get the closest value: >> Z = 10.7000; >> ACF = [0,-1...

10 years ago | 0

| accepted

Answered
Large data file with mixed character strings and numerical formats
Do not use |fgetl| or |fgets|: on such a large file as this would be very slow. Use <https://www.mathworks.com/help/matlab/ref/t...

10 years ago | 0

| accepted

Answered
How can I tell the user to re-input their prompt, if their prompt does not satisfy a condition?
It is a bad practice to call |input| without the |s| option, because it will evaluate any arbitrary code, and also will produce ...

10 years ago | 1

| accepted

Answered
Vector/matrix Initialization
The first two blocks don't make much sense. Assuming that the one of those |if| conditions is true then vector |k| will get defi...

10 years ago | 1

| accepted

Answered
How can I know the new value of y after spline interpolation?
According to the <https://www.mathworks.com/help/curvefit/csaps.html |csaps|> documentation (part of the Curve Fitting toolbox),...

10 years ago | 0

| accepted

Answered
Efficiently Read in Text file with Headers Throughout File
Without reading the file first, importing both headers and numeric data, and using |textscan| to make it nice and fast: A =...

10 years ago | 1

Answered
How to append new structure array element in existing .mat file.
You might find that <http://www.mathworks.com/help/matlab/ref/matfile.html |matfile|> is the easiest way. There are lots of exam...

10 years ago | 3

| accepted

Answered
Replace elements in a SxS matrix with zero, in each column but in different rows
This is simple using either the FEX submission <https://www.mathworks.com/matlabcentral/fileexchange/24536-expand |expand|>: ...

10 years ago | 1

| accepted

Answered
How can I use a string input in a "for" loop to get a matrix of names?
Your code has multiple mistakes: MATLAB indexing starts from one, you need to use a |for| loops, and you need to use a cell arra...

10 years ago | 1

Answered
How to convert cell into array of floating point numbers only?
One simple solution is to use my FEX submission <https://www.mathworks.com/matlabcentral/fileexchange/53886-scientific-prefix-to...

10 years ago | 0

Answered
restate in logical indexing
One way would be to use <https://www.mathworks.com/help/matlab/ref/sub2ind.html |sub2ind|>, which generates linear indices (not ...

10 years ago | 1

| accepted

Answered
Transforming a 3d array
reshape(B,[100,100,60]) or permute(B,[1,3,2]) where |B| is the second array. Note that the answer depends on _how_ ...

10 years ago | 1

| accepted

Answered
How to substitute multiple values to the same size variables
If you really want to do that then put the values into a cell array first: >> X = {1,2,3}; >> [a,b,c] = X{:}; >> ...

10 years ago | 2

| accepted

Answered
How can I remove a value from an array but keeping an empty slot
Method One: replace with NaN (best solution): a = [1;2;3]; a(2) = NaN; Method Two: store a mask: a = [1;2;3] mask...

10 years ago | 1

| accepted

Answered
How to make vectors zero when adding two different size vectors?
function Z = adding(A,B) d = numel(A)-numel(B); Z = [zeros(1,-d),A] + [zeros(1,d),B]; end and tested: >> addi...

10 years ago | 0

| accepted

Answered
How to link two arrays?
Assuming that the elements are unique, then <https://www.mathworks.com/help/matlab/ref/ismember.html |ismember|> will work: ...

10 years ago | 1

| accepted

Answered
line color in figure
If you plot all of the lines at once then they will automatically be colored using the <https://www.mathworks.com/help/matlab/re...

10 years ago | 0

Answered
For loop problem.
abs(diff(a,1)) and then play around with |sum|. For example: >> A = randi(9,5,10) A = 8 1 7 6 2 3 ...

10 years ago | 1

Answered
How to make coupled data
<https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html Array preallocation> and two loops will do the tric...

10 years ago | 0

| accepted

Answered
How do I make a matrix based on two other matrices and an equation with three conditions?
You forgot to use indexing to store the values into your matrix, and you also made the mistake of naming a variable with the sam...

10 years ago | 0

Answered
how to read all my audio file from one directory and store the outputs for all the files in one variable (matrix) ??????????
Using my FEX submssion natsortfiles to get the correct file order (untested): P = './audio'; % absolute or relative path to wh...

10 years ago | 2

| accepted

Answered
how to find the no of colors and name of the colors in an object eg: tomato
Perform <https://www.mathworks.com/matlabcentral/answers/79147-how-to-color-correct-an-image-from-with-a-color-checker white/col...

10 years ago | 0

| accepted

Answered
Size input must be scalar error while using rand
The syntax you use does not work because |k| is a vector. Taking a wild stab in the dark: for k = 2:5 A = rand(k,4); ...

10 years ago | 0

| accepted

Answered
if i have two vectors that result in a matrix that is 40x5 but i want the dimensions flipped, how would i do that
You can use <https://www.mathworks.com/help/matlab/ref/transpose.html transpose>: M.' where M is the matrix.

10 years ago | 1

Answered
How to write a program, and shuffles only the inner letter of the word?
>> str = 'This is really quite easy with regular expressions.'; >> regexprep(str,'(\w)(\w+)(\w)','$1${$2(randperm(numel($2)...

10 years ago | 2

Answered
How do I change the name of the different figure window from "Figure 1","Figure 2"... to user defined names?
Set the |'Name'| <https://www.mathworks.com/help/matlab/ref/figure-properties.html figure property>: fgh = figure('Name','Pu...

10 years ago | 0

| accepted

Answered
How do I replace/manipulate characters in a string? Specifically integers in a string...
One easy way with <https://www.mathworks.com/help/matlab/ref/regexprep.html |regexprep|>: >> str = 'F18-F4+F'; >> regexp...

10 years ago | 1

| accepted

Answered
What is wrong with my function?
You need to use a |while| loop, not a |for| loop. And you need to learn to indent your code consistently and use code comments t...

10 years ago | 0

Load more