Answered
Replace NaN with median per column
M = randi(3,5,7); M(randi(numel(M),1,9)) = NaN V = median(M,1,'omitnan') X = isnan(M); M(X) = repelem(V,sum(X,1))

5 years ago | 1

Answered
How i can combine three or more than three matrix?
Note that you will run out of memory very quickly as you increase the number of matrices. format compact inp = {rand(3,4),rand...

5 years ago | 0

| accepted

Answered
'Merge' two cell arrays into one single cell array (NOT concatenation!)
c1 = {[1;2],5} c2 = {[3;4],[6;7;8;9;10]} out = cellfun(@vertcat,c1,c2,'uni',0) celldisp(out)

5 years ago | 0

| accepted

Answered
How I can create this matrix?
X = A(:,5)<1; A(X,:) = []

5 years ago | 1

| accepted

Answered
return matrix rows and columns using a one-to-one mapped vector for rows and vector for column
Use sub2ind: idx = sub2ind(size(A),pnRowsToSelect,pnColsToSelect); out = A(idx)

5 years ago | 0

| accepted

Answered
Convert Time Given in Seconds to Minute, Seconds, Milliseconds
If you really need minutes (i.e. and not roll-over to hours for >59 minutes) then you can calculate this yourself, e.g.: inp = ...

5 years ago | 0

Answered
replace specific commas using strrep
"I converted my data... using str2num." Although your descriptiion is unclear, I guess that your goal to convert text data into...

5 years ago | 0

Answered
How can I create this matrix?
n = 5; r = 2:5; F = @(k)any(permute(nchoosek(1:n,k),[3,1,2])==(1:n).',3); M = cell2mat(arrayfun(F,r,'uni',0))

5 years ago | 1

| accepted

Answered
Effective matrix defining (diagonals)
N = 7; M = toeplitz([-2,1,zeros(1,N-2)])

5 years ago | 1

| accepted

Answered
Remove String and extract numbers to move to new column
S = [... "[0, 0]" "[0, 5]" "[5, 115]" "[115, 219]" "[219, 262]" "[262, 328]" "[328, 408]" "[408, 424]" "[424, 531]" "[...

5 years ago | 0

| accepted

Answered
Help with regexp to extract data
tdata = {'W1W','W1W 7','W1W 8','AZ_85262','CA_90032','CA_90045'}; tkn = regexp(tdata,'^(.*?)_?([^_]*)$','tokens','once'); tkn ...

5 years ago | 0

| accepted

Answered
complicated formatted text with textscan
I removed the extra line of numbers from block 3, the modified data file is attached. This code imports the modified data file:...

5 years ago | 0

| accepted

Answered
How to cut multiple file ans past it to folder?
mkdir 4ASK movefile frame4ASK*.m 4ASK

5 years ago | 0

Answered
Using cell array for indexing
No need for a loop, here is the simple and efficient MATLAB approach: IndArray = {i1,..,im}; IndArray(1+end:ndims(A)) = {':'};...

5 years ago | 1

Answered
How to organize an array (x_i,y_j,z) such that (x_i,y_i)=z?
The trick is to use https://www.mathworks.com/help/matlab/ref/sub2ind.html A = [1,1,2;1,2,0.5;2,1,0.5;2,2,1] S = max(A(:,1:2),...

5 years ago | 0

| accepted

Answered
why "writetable" replaces points with commas ???
"why "writetable" replaces points with commas ???" It doesn't. The Open Office XML format (e.g. XLSX) uses only the decimal po...

5 years ago | 1

Answered
'123' to 123
A = '123' A = str2double(A)

5 years ago | 0

| accepted

Answered
Indexing a variable in a cell array?
strcmpi(txt2,date) But... you should be using READTABLE to import that file data, and handle those dates as DATETIME, not as ...

5 years ago | 0

Answered
Add variables calculated in a for loop into an array
I suspect that you need something like this: nml = numel(numbers); out = nan(nml,1); for k = 1:nml out(k) = calculate(nu...

5 years ago | 0

| accepted

Answered
How can I change the line color in a graph using plot
You are using MATLAB R2014a, which uses the old graphics system. That YouTube tutorial uses R2015b, which includes a totally ne...

5 years ago | 0

Answered
Get number of fields? the result should be 14! I tried with size but it did not work!
"I tried with size but it did not work!" The size of a structure is completely independent of how many fields it has. To count...

5 years ago | 0

Answered
Select particular elements from a cell array to form a matrix (double type)
Simply: fun = @(x) x.endo_simul(17,1); out = cellfun(fun,results)

5 years ago | 1

Answered
What is the most correct way of determining whether variable contains a number
Let MATLAB do the heavy lifting for you: fun = @(x) isnumeric(x)&&isfinite(x) || isfinite(str2double(x)); fun(2.3) fun(NaN) ...

5 years ago | 0

Answered
How to create exportable table from outputs of function iterated using for loop?
If your function has four outputs then you need to call it with four outputs. This is explained in the introductory tutorials: ...

5 years ago | 0

| accepted

Answered
How to reshape 3D matrix ?
A = randi(9,4,4,3) B = permute(reshape(permute(A,[2,1,3]),[2,8,3]),[3,1,2])

5 years ago | 0

| accepted

Answered
Where can I download apiref.pdf
This PDF file: https://www.mathworks.com/help/pdf_doc/matlab/matlab_apiref.pdf is listed here: https://www.mathworks.com/help...

5 years ago | 0

| accepted

Answered
Why is my loop not working?
Look closely at the variable a: a=0; for .. a=a+50; [b,a]=ellip(..[a 5000]..); .. end At the start of the fir...

5 years ago | 0

| accepted

Answered
Merge a row to a single cell
C = {... '1' '2' ':' '5' '7' ':' '0' '0' '1' '2' ':' '5' '7' ':' '0' '0' '1' '2' ':' '5' '7' ':' '0' '0' '1'...

5 years ago | 0

| accepted

Answered
The size of the indicated variable or array appears to be changing with each loop iteration. Commonly, this message appears because an array is growing by assignment or concat
h = 1; r = 0:h:20; z = 0:h:20; [rgrid,zgrid] = meshgrid(r,z); zgrid = flip(zgrid) Simpler, faster code: b2 = find(zgri...

5 years ago | 0

| accepted

Answered
What does this mean "No differences to display. The files are not identical, but the only differences are in end-of-line characters."
"Can anyone help me to understand the meaning? " When you look at those files then they are shown with lots of lines. You might...

5 years ago | 1

| accepted

Load more