Answered
How to display each element of an array as an output?
>> S(1).f = 4; >> S(2).f = 2; >> S(3).f = 3; >> S(4).f = 1; >> C = num2cell(sort([S.f])); >> [S.f] = C{:}; >...

9 years ago | 0

Answered
How can I use regexp to return a list of variable names?
I used <https://www.mathworks.com/help/matlab/ref/regexpi.html |regexpi|> for simplicity: >> str = 'var1 * _var2 * 2var3 + ...

9 years ago | 0

Answered
Find where data is above threshold continuously and for how long using logical indexing
So you have some data vector, and a threshold. First thing is to generate a logical vector: V = data > threshold; then y...

9 years ago | 0

| accepted

Answered
How to plot a broken horizontal line (ie, a horizontal line with whitespace)
NaN values are not plotted, so all you need is to plot a vector with NaNs in the location that you do not want plotted: V =...

9 years ago | 0

Answered
True false results to be saved as a value
Simplest would be to just multiply the logical vector by 0.25: >> a = [1,0,1,1,1,0,0,0]; >> b = a*0.25 b = 0.25 ...

9 years ago | 1

| accepted

Answered
using cla in a for loop
When you call <https://www.mathworks.com/help/matlab/ref/cla.html |cla|> it removes _everything_ in the axes, including the <htt...

9 years ago | 1

| accepted

Answered
Why can i not add these arrays to a matrix
You could convert the numeric array |P| into a cell array: [ILM,SDG,ID,num2cell(P)] But keep in mind that storing numeri...

9 years ago | 0

| accepted

Answered
Downloading csv file takes too much memory?
# <https://www.mathworks.com/help/matlab/import_export/import-large-text-files.html> # <https://www.mathworks.com/help/matlab/d...

9 years ago | 0

Answered
Replace zeros with text
_"Is there a way to create a cell array that is n rows long that contains 'hello' in each row?"_ repmat({'hello'},n,1)

9 years ago | 1

Answered
Binary to floating point representation using IEEE-754
It is simple to avoid the loop: S = '10101110101101011010010110101001'; %S = '00111110001000000000000000000000'; % Wikip...

9 years ago | 2

| accepted

Answered
Hi, i have cell that consisting string value.i want to use every cell element as variable name. for example filename{1}= [1 2 3] then i have EX1=[1 2 3] in work space. i wrote this code but it doesn't work.
As an alternative to magically creating variable names (which is <https://www.mathworks.com/matlabcentral/answers/304528-tutoria...

9 years ago | 0

| accepted

Answered
Splitting Column into Several Columns in Matlab
Where |M| is your matrix, and assuming that the number of rows of |M| is divisible by 180: reshape(M(:,5),180,[]) If the...

9 years ago | 0

Answered
Vector input, 1 output
theta4 = 2*atand(num./den); ^ element-wise divide

9 years ago | 0

Answered
Is there a way I can get my code to display the function chosen in fprintf?
It is not necessary to jump into using the symbolic toolbox for every little problem: that would be overkill for such a simple p...

9 years ago | 2

| accepted

Answered
Read value from a text file and store into an array
Use <https://www.mathworks.com/help/matlab/ref/dlmread.html |dlmread|>: >> M = dlmread('BusData8.txt','',1,0) M = ...

9 years ago | 1

| accepted

Answered
How to sort the struct array after reading number of images using dir command
"I am reading images thru 'dir' command from a folder but those are unsorted , I am expecting them as sorted...." The order of ...

9 years ago | 2

| accepted

Answered
Is it possible to sort an array by making the repeated elements in the last?
>> A = [-2,-2,-1,3,3,3,9,9,0,99] A = -2 -2 -1 3 3 3 9 9 0 99 >> [cnt,idx] = histc(A,unique...

9 years ago | 0

| accepted

Answered
How to make a for loop run consecutively?
Using a loop and removing one element at a time is very inefficient, because you force MATLAB to move the array in memory each t...

9 years ago | 1

| accepted

Answered
Construct a filename and then open it
Using cd makes code slow and harder to debug: instead of using cd simply use faster and more reliable relative/absolute filename...

9 years ago | 0

| accepted

Answered
Testing whether values are unique
MATLAB works best when data is kept together as much as possible, not split into lots of separate variables. The solution is eas...

9 years ago | 3

| accepted

Answered
How can I do this matrix ?
>> A = [1;6;9;4;2;8]; >> M = tril(repmat(A.',6,1)) M = 1 0 0 0 0 0 1 6 0 0 0 0 1...

9 years ago | 1

| accepted

Answered
How to repeat calculations and store answers
You should write simple <https://www.mathworks.com/help/matlab/matlab_prog/vectorization.html vectorized code>, e.g.: X = [...

9 years ago | 0

| accepted

Answered
How to adjust the "isnan" to make it work for cell?
Don't waste your time with cell arrays and |cell2mat| and the like, you don't need them. Just use a numeric variable: N = s...

9 years ago | 2

| accepted

Answered
To avoid global variables, which is the best way to share variables among functions in a GUI in Matlab:
I recommend using <https://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html nested functions>: simple, intuitive,...

9 years ago | 0

Answered
How can I extract zero values from a big Matrix
Use <https://www.mathworks.com/help/matlab/ref/interp2.html |interp2|> and <https://www.mathworks.com/help/matlab/ref/fzero.html...

9 years ago | 1

| accepted

Answered
Check if two colors are similar
There is no simple solution to this because human eyes (like all other animal eyes) are very non-linear, and our perceptual resp...

9 years ago | 3

Answered
Replace String Value in Cell with Numerical Value
A = {'Inf','C.C3','C.C2',1;'-Inf',1,'C.C5','Inf';'C.C4',0,0,'-Inf';0,0,1,'-Inf'}; idn = cellfun(@isnumeric,A); % identify n...

9 years ago | 1

| accepted

Answered
Inputdlg requesting input to provide an output of 6 integers as a row vector
Do NOT use |str2num|! Using |sscanf| is faster than |str2num| (and avoids the internal |eval| call that |str2num| hides inside):...

9 years ago | 0

| accepted

Answered
hi everyone , how can I built a matrix of circularly shifted array in efficient way
Multiple |circshift| calls in a loop is not required. One call to <https://www.mathworks.com/help/matlab/ref/toeplitz.html |toep...

9 years ago | 1

| accepted

Answered
hi. i am trying to use natsortfile() function to sort filenames in ascending order. error shown is 'undefined variable or function name'. kindlly help.
natsortfiles is not an inbuilt MATLAB function: you must download it, unzip it, and put both Mfiles on your MATLAB Search Path (...

9 years ago | 2

| accepted

Load more