Answered
Plotting struct with out first line
>> X = [s(2:end).a]; >> Y = [s(2:end).b]; >> plot(X,Y) >> xlabel(s(1).a) >> ylabel(s(1).b) Read these to know more: http...

7 years ago | 1

| accepted

Answered
get the index of the n one in a binary vector
>> bv=[0,0,0,0,1,0,0,1,1,1,0,0,1,0,1]; >> idx = find(bv); >> idx(4) ans = 10

7 years ago | 0

Answered
How to structure input data as what I need?
str = fileread('store.txt'); str = strtrim(str); C = regexp(str,'\s*,\s*','split'); [fid,msg] = fopen('store2.txt','wt'); as...

7 years ago | 1

| accepted

Answered
nargin doesn't work with my settings
"nargin doesn't work" nargin does work. MATLAB input arguments are (for better or for worse) entirely positional. Inputs are n...

7 years ago | 1

| accepted

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...

7 years 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); >...

7 years ago | 2

| 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>=...

7 years ago | 0

| accepted

Answered
folder split into parts
In two lines: movefile('Prostatex0000_*.nii','subdir0') movefile('Prostatex0001_*.nii','subdir1')

7 years 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 ...

7 years ago | 0

| accepted

Answered
Flipping specific segment of string rather than the whole string
regexprep(str,'\w+','${fliplr($0)}')

7 years 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...

7 years 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....

7 years ago | 0

| accepted

Answered
choose row cell of matrix
A general solution in one line: C = cellfun(@(r)A(r,:),B,'uni',0)

7 years 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...

7 years ago | 3

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)

7 years 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...

7 years 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 >> ...

7 years 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 ...

7 years ago | 2

| accepted

Answered
How to create and load a custom colormap?
Assuming that mymap is a variable in the workspace: colormap(gca,mymap);

7 years ago | 2

| 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...

7 years 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)...

7 years 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 ...

7 years 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...

7 years 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*(...

7 years ago | 0

Answered
Saving file issue while trying to add variables
You are saving to different files: save(mysave,...) save(filename,...)

7 years 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:

7 years 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...

7 years 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

7 years 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 ...

7 years 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 = ...

7 years ago | 2

Load more