5,229 total contributions since 2014

Suspensa Vix Via Fit

Answered

Plotting n-by-m matrix

Good question. I also faced this issue a few years ago, and I found the simplest solution was to append NaN onto the bottom of t...

Plotting n-by-m matrix

Good question. I also faced this issue a few years ago, and I found the simplest solution was to append NaN onto the bottom of t...

2 days ago | 0

| accepted

Answered

Add a zero element to the beginning of each existing cell array

cellfun(@(v)[0;v],C,'uni',0) And checking: >> C = {[-8;-5],[1;-4;-5;-5;-5],[-3;-5]}; >> CC = cellfun(@(v)[0;v],C,'uni',0); >...

Add a zero element to the beginning of each existing cell array

cellfun(@(v)[0;v],C,'uni',0) And checking: >> C = {[-8;-5],[1;-4;-5;-5;-5],[-3;-5]}; >> CC = cellfun(@(v)[0;v],C,'uni',0); >...

2 days ago | 1

| accepted

Answered

I am having a error using fprintf

You should always return the second output of fopen and check the f_id value: [f_id,msg] = fopen(txt_name,'wt'); assert(f_id>=...

I am having a error using fprintf

You should always return the second output of fopen and check the f_id value: [f_id,msg] = fopen(txt_name,'wt'); assert(f_id>=...

3 days ago | 0

| accepted

Answered

folder split into parts

In two lines: movefile('Prostatex0000_*.nii','subdir0') movefile('Prostatex0001_*.nii','subdir1')

folder split into parts

In two lines: movefile('Prostatex0000_*.nii','subdir0') movefile('Prostatex0001_*.nii','subdir1')

3 days ago | 0

| accepted

Answered

How to store the result of a loop in a cell?

Your code is only iterating once, because for i = 1:44 ^^ you forgot this. PS: I would recomend using ii or k as the ...

How to store the result of a loop in a cell?

Your code is only iterating once, because for i = 1:44 ^^ you forgot this. PS: I would recomend using ii or k as the ...

3 days ago | 0

| accepted

Answered

Flipping specific segment of string rather than the whole string

regexprep(str,'\w+','${fliplr($0)}')

Flipping specific segment of string rather than the whole string

regexprep(str,'\w+','${fliplr($0)}')

3 days ago | 2

Answered

I am getting an error as "Operands to the || and && operators must be convertible to logical scalar values. Error in xd (line 8) if (t>=t1)&&(t<t2)".

Learn to use logical indexing https://www.mathworks.com/help/matlab/getting-started-with-matlab.html Logical indexing is a ver...

I am getting an error as "Operands to the || and && operators must be convertible to logical scalar values. Error in xd (line 8) if (t>=t1)&&(t<t2)".

Learn to use logical indexing https://www.mathworks.com/help/matlab/getting-started-with-matlab.html Logical indexing is a ver...

3 days ago | 1

Answered

Reading a number from text file

>> str = fileread('MASS.txt'); >> tmp = regexp(str,'(?<=X\s+)\d+\.?\d*E[-+]\d+','match','once'); >> str2double(tmp) ans = 3....

Reading a number from text file

>> str = fileread('MASS.txt'); >> tmp = regexp(str,'(?<=X\s+)\d+\.?\d*E[-+]\d+','match','once'); >> str2double(tmp) ans = 3....

3 days ago | 0

| accepted

Answered

choose row cell of matrix

A general solution in one line: C = cellfun(@(r)A(r,:),B,'uni',0)

choose row cell of matrix

A general solution in one line: C = cellfun(@(r)A(r,:),B,'uni',0)

3 days ago | 0

| accepted

Answered

How to plot an empty 2-D cartesian grid on its own ?

>> axes() >> xlim([200,455]) >> ylim([50,305]) >> grid on >> grid minor Or alternatively in one axes call: axes('XLim',[20...

How to plot an empty 2-D cartesian grid on its own ?

>> axes() >> xlim([200,455]) >> ylim([50,305]) >> grid on >> grid minor Or alternatively in one axes call: axes('XLim',[20...

3 days ago | 0

Answered

How can I convert matrix in cell array to same size cell array within the original array without for loop?

Where C is your 4x1 cell array: D = cellfun(@num2cell,C,'uni',0)

How can I convert matrix in cell array to same size cell array within the original array without for loop?

Where C is your 4x1 cell array: D = cellfun(@num2cell,C,'uni',0)

4 days ago | 0

| accepted

Answered

how to flip a general square matrix ( it could have even or odd number of rows/cols ) from it's center in matlab ?

>> M = [1,2,3,4,5;2,6,7,9,10;3,7,11,12,13;4,9,12,16,20;8,10,13,20,25] M = 1 2 3 4 5 2 6 7 9 10...

how to flip a general square matrix ( it could have even or odd number of rows/cols ) from it's center in matlab ?

>> M = [1,2,3,4,5;2,6,7,9,10;3,7,11,12,13;4,9,12,16,20;8,10,13,20,25] M = 1 2 3 4 5 2 6 7 9 10...

4 days ago | 0

| accepted

Answered

how to convert to a cell array from a single precision array

Simpler to use num2cell: >> a = [1.1,1.2;2.1,2.2;3.1,3.2] a = 1.1000 1.2000 2.1000 2.2000 3.1000 3.2000 >> ...

how to convert to a cell array from a single precision array

Simpler to use num2cell: >> a = [1.1,1.2;2.1,2.2;3.1,3.2] a = 1.1000 1.2000 2.1000 2.2000 3.1000 3.2000 >> ...

4 days ago | 2

Answered

Why do I have to type '^' plus the next character two times?

This behavior is perfectly normal. It depends solely on your language and keyboard settings. Some keyboards use the ^ key (and ...

Why do I have to type '^' plus the next character two times?

This behavior is perfectly normal. It depends solely on your language and keyboard settings. Some keyboards use the ^ key (and ...

5 days ago | 2

| accepted

Answered

How to create and load a custom colormap?

Assuming that mymap is a variable in the workspace: colormap(gca,mymap);

How to create and load a custom colormap?

Assuming that mymap is a variable in the workspace: colormap(gca,mymap);

5 days ago | 1

| accepted

Answered

Cell array: select only 1x3 double cells

Where C is your cell array: X = cellfun('length',C)==3; out = C(X) https://www.mathworks.com/help/matlab/matlab_prog/access-d...

Cell array: select only 1x3 double cells

Where C is your cell array: X = cellfun('length',C)==3; out = C(X) https://www.mathworks.com/help/matlab/matlab_prog/access-d...

5 days ago | 0

| accepted

Answered

find array inside a cell

Simpler in one line: >> A = {[1,2,4],[2,3,7],[2,5],[4,5,6]}; >> B = [1;2;3;6;8]; >> C = cellfun(@(m)intersect(m,B),A,'uni',0)...

find array inside a cell

Simpler in one line: >> A = {[1,2,4],[2,3,7],[2,5],[4,5,6]}; >> B = [1;2;3;6;8]; >> C = cellfun(@(m)intersect(m,B),A,'uni',0)...

5 days ago | 0

| accepted

Answered

What next in the code

Your function definitions are not correct. Instead of this invented syntax: Function 1 [W] = Naturalfreq(k,m) ... your code ...

What next in the code

Your function definitions are not correct. Instead of this invented syntax: Function 1 [W] = Naturalfreq(k,m) ... your code ...

5 days ago | 0

Answered

Is there an efficient way to create a matrix with all permutations of inserting one array into another?

Perhaps something like this: >> A = [1,5,6]; % remaining >> B = [4,3,2]; % reversed >> N = numel(A); >> M = toeplitz([B,zero...

Is there an efficient way to create a matrix with all permutations of inserting one array into another?

Perhaps something like this: >> A = [1,5,6]; % remaining >> B = [4,3,2]; % reversed >> N = numel(A); >> M = toeplitz([B,zero...

6 days ago | 1

| accepted

Answered

Nested Indexing in a Single Line command

>> C = {'George: A5 == BB'; 'Anna: C3 == DD'; 'Smith: E2 == FFF'; 'Ken: G8 == HHHH'}; >> D = regexp(C,'^(\w+):\s*(\w+)\s*==\s*(...

Nested Indexing in a Single Line command

>> C = {'George: A5 == BB'; 'Anna: C3 == DD'; 'Smith: E2 == FFF'; 'Ken: G8 == HHHH'}; >> D = regexp(C,'^(\w+):\s*(\w+)\s*==\s*(...

6 days ago | 0

Answered

Calculate different rowss in a matrix

B = [A(1:30,:)*10;... A(31:180,:)*5;... A(181:300,:)*10]

Calculate different rowss in a matrix

B = [A(1:30,:)*10;... A(31:180,:)*5;... A(181:300,:)*10]

6 days ago | 0

Answered

Saving file issue while trying to add variables

You are saving to different files: save(mysave,...) save(filename,...)

Saving file issue while trying to add variables

You are saving to different files: save(mysave,...) save(filename,...)

6 days ago | 0

| accepted

Answered

How can i find helper functions in Matlab?

At the bottom of the page, in a section entitled "Appendix", you will find the links to those functions:

How can i find helper functions in Matlab?

At the bottom of the page, in a section entitled "Appendix", you will find the links to those functions:

6 days ago | 0

Answered

Add new elements into cell array inside a loop

This will store the data each iteration of both loops (but I did not change the logical conditions): N = size(TestData,1); % mu...

Add new elements into cell array inside a loop

This will store the data each iteration of both loops (but I did not change the logical conditions): N = size(TestData,1); % mu...

6 days ago | 0

Answered

Count number of repeated element before next different number in array?

>> D = diff([0,A==1,0]); >> find(D<0)-find(D>0) ans = 3 1 2 4

Count number of repeated element before next different number in array?

>> D = diff([0,A==1,0]); >> find(D<0)-find(D>0) ans = 3 1 2 4

6 days ago | 0

| accepted

Answered

Subscript indices must either be real positive integers or logicals.

Better to iterate over integer indices rather than fractional values: V = 1:0.1:20; N = numel(V); M = nan(N,3); for k = 1:N ...

Subscript indices must either be real positive integers or logicals.

Better to iterate over integer indices rather than fractional values: V = 1:0.1:20; N = numel(V); M = nan(N,3); for k = 1:N ...

6 days ago | 0

| accepted

Answered

i have one variable which has value in an array and i want to make the power of all the value of array by another variable but getting value zero.any possible solution?

"any possible solution?" Solution to what, exactly? You calculate this (the loop is not required): >> alpha.^lambda ans = ...

i have one variable which has value in an array and i want to make the power of all the value of array by another variable but getting value zero.any possible solution?

"any possible solution?" Solution to what, exactly? You calculate this (the loop is not required): >> alpha.^lambda ans = ...

6 days ago | 2

Answered

Horizontally concatinating the fields of a structure with different dimensions.

The different number of rows does not prevent them from being concatenated vertically: >> S.f1 = [0,1;2,3;4,5]; >> S.f2 = [6,7...

Horizontally concatinating the fields of a structure with different dimensions.

The different number of rows does not prevent them from being concatenated vertically: >> S.f1 = [0,1;2,3;4,5]; >> S.f2 = [6,7...

6 days ago | 0

| accepted

Answered

How to change string name?

The solution is to simply use indexing. For example, you could put all of your imported data into one cell array. You did not gi...

How to change string name?

The solution is to simply use indexing. For example, you could put all of your imported data into one cell array. You did not gi...

7 days ago | 2

| accepted

Answered

How to extract locations from strings of addresses?

Using one simple regular expression: >> C = {... 'Sustainable Industrial Systems, School of Chemical Engineering and Analyti...

How to extract locations from strings of addresses?

Using one simple regular expression: >> C = {... 'Sustainable Industrial Systems, School of Chemical Engineering and Analyti...

7 days ago | 1

| accepted