Answered
Can someone help me with this question? I keep getting the error "Not enough input arguments. Error in assesment2question1 (line 5) for m = 1:N"
The simple solution using an anonymous function: >> func = @(x,N) sum(bsxfun(@power,x,(1:N).'),1); >> X = -0.5:0.1:0.5; >> pl...

7 years ago | 0

Answered
How can i allocate results in matrix with for loop?
This is MATLAB, so just get rid of the pointless loops entirely: >> w = 0:4; >> t = 0:9; >> y = exp(t.*w(:).*1i) y = Col...

7 years ago | 0

| accepted

Answered
assigning value to a changing struct field
ytpe = {'P','G'}; % more robust as cell array. axis = {'x','y','z'}; % more robust as cell array. for ii = 1:numel(ytpe) ...

7 years ago | 0

Answered
Basic operations with matrices
Assuming that each .mat file contains only one variable and there are no other similarly named .mat files in the same directory:...

7 years ago | 1

| accepted

Answered
how to reverse the process of matrix conversion to structure?
This is MATLAB, so loops are not required: rows = 480; cols = 800; MAT = randi(9,rows,cols); % fake data matrix Rb = 16; % ...

7 years ago | 2

| accepted

Answered
how to match and eliminate those values??
"i am not able to understand this" Your code: find(codes~=s)) first creates a logical array with the same size as codes, with...

7 years ago | 1

| accepted

Answered
How to import an equation that is user defined in GUI into separate m files?
Use str2func to generate a nice function handle that you can use/pass to your other code. Note that you will need to prefix the...

7 years ago | 1

Answered
syntax to used unmatched values in matlab?
Method one: setdiff: >> s = [1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0] s = 1 1 0 0 0 0 1 1 0 0 1 1 1 1 ...

7 years ago | 0

Answered
How can I increase the precision of the y axis?
yticks(-5:5)

7 years ago | 0

| accepted

Answered
Why does function isscalar() return "1" for function handles?
Because the documentation states that "A function handle is always scalar (1-by-1)." https://www.mathworks.com/help/matlab/matl...

7 years ago | 2

| accepted

Answered
Interp1 on a cell array
>> A = {[],[],4,5,6,7,[],[],8,[],5,[],[]}; >> idx = find(~cellfun('isempty',A)); >> idy = idx(1):idx(end); >> new = interp1(i...

7 years ago | 1

| accepted

Answered
why is there a smiley face when use imagesc
That is not a smiley face, it is a photo of Steve Eddins' eldest son: https://blogs.mathworks.com/steve/2006/10/17/the-story-be...

7 years ago | 1

| accepted

Answered
How do I compare the result of the output of a loop with the previous output of the loop?
Put your entire if... ifelse ... end inside another if: if i>1 if size(...) ... elseif size(...) .....

7 years ago | 0

| accepted

Answered
How do I store matrices into a cell array in the correct order?
"When I store the cell array, for some reason the elements are stored in reverse order." Not at all. They are stored in the exa...

7 years ago | 0

| accepted

Answered
How can I count the word "the" in a paragraph (a ".txt" file) creating an array?
This actually works: >> C = regexp('the cat in the hat','\s+','split'); >> nnz(strcmpi(C,'the')) ans = 2

7 years ago | 0

Answered
Concatenation is missing values
33 of the cells in the third column contain empty arrays: >> find(cellfun('isempty',cellStruct(:,3))) ans = 21968 2196...

7 years ago | 2

| accepted

Answered
How to create a string with names that differ, without a loop?
The fastest solution is to use the undocumented function sprintfc: sprintfc('K%d',1:39) As this is undocumented, use at your o...

7 years ago | 1

| accepted

Answered
How to concatenate tables with the same number of variables but different number of rows?
Assuming that the data have the same class, that each .mat file contains the same four variables, and that within any one mat fi...

7 years ago | 0

Answered
How do I use two arrays to lookup the value from a third array?
Here is a general solution based on sub2ind, for any row and column indices: >> row = 1:10; >> col = 10:-1:1; >> mat = rand(1...

7 years ago | 0

| accepted

Answered
How to index this matrix ?
Several years ago I wrote an efficient function that returned the linear indices corresponding to any ND indices returned by min...

7 years ago | 0

Answered
How do I flip the order of cells in a cell array?
Simpler: C(end:-1:1) = C(:) or C = flip(C)

7 years ago | 5

Answered
combining specific elements in an array
Assuming that the number of digits is always the same.... Method one: reshape and matrix multiply: >> V = [16, 29, 0.599, 16, ...

7 years ago | 0

| accepted

Answered
finding the increase in values
a = [2;2;2;3;3;3;5;5;5;4;4;3;3;3;2;2;3;3;3;4;4;4;5;5;5;4;4;3;3] idx = [true;diff(a)~=0]; idy = diff(a(idx))>0; idd = diff([0;...

7 years ago | 0

| accepted

Answered
generating matrices of the possible combinations
X = [1,7,9,10,15;4,8,5,9,21;2,14,3,6,16] P = nchoosek(1:5,3) N = size(P,1); C = cell(1,N); for k = 1:N C{k} = X(:,P(k,:...

7 years ago | 1

| accepted

Answered
User defined function with vector inputs returns incorrect values?
if length(n) > 1 ... return % add this! end The reason is simple: you detect when n is non-scalar, and inside that ...

7 years ago | 0

| accepted

Answered
How to calculate the memory required by struct, numerical and char arrays? Kindly share the formula?
The documentation explains how much memory is required for cell arrays and structure arrays: https://www.mathworks.com/help/mat...

7 years ago | 1

Answered
Why does 7*(0.1) - 0.7 = 1.1102e-16 whereas 9*(0.1)-0.9 =0 in MATLAB?
Those values that you are computing with cannot be exactly represented using binary floating point numbers. What you see printed...

7 years ago | 4

Answered
Hello.......i have a matrix.......what i wonaa do is count the repeated entries in column 2 first then make arrangement =(number of repeated termes)! ..for example in given matrix i have two repeated terms so first arrangmnt..1 2 3 the second 2 1 3
Interesting problem. I used a slightly more complex example, with two values duplicated (4 twice, 9 thrice), for which we would ...

7 years ago | 1

| accepted

Answered
How to skip [] when add values to a vector variable?
str = input('Enter values x y: ','s'); vec = sscanf(str,'%f')

7 years ago | 0

Answered
How do I create a for loop that can use multiple changing variables?
... b = 0:pi/80:pi/8; c = 0:pi/40:pi/4; d = 0:3*pi/80:3*pi/8; e = 0:pi/20:pi/2; for k = 1:numel(b) pause(0.5) B =...

7 years ago | 0

| accepted

Load more