Answered
Problem with calculating a product of a random vector using a For loop. Help, Urgent!
RunSum = RunSum*Vect(n); : disp(RunSum) Although, I think the instructions meant for your code to use the ...

9 years ago | 1

| accepted

Answered
User defined function that fits an nth order polynomial curve to given data for values of n<30
Start with this: - Create a function m-file in your working directory: edit curvepoly.m - Put the following code into...

9 years ago | 0

Answered
xyz coordinate to angle.
doc cart2sph

9 years ago | 1

Answered
How can I calculate the standard deviation of a LARGE set of values without using the' std' or 'mean' commands?
You've got the ^2 in the wrong place in your calculation. Also, the std function uses n-1 in the denominator by default. Try thi...

9 years ago | 0

| accepted

Answered
I want this string to be different every time.
n = number of values to generate b = round(rand(1,n)); % vector randomly filled with 0's and 1's s = char(b+'0'); % a c...

9 years ago | 0

| accepted

Answered
Clarification: Array of strings vs cell array of character vectors
Generally, if you will be accessing the individual strings downstream in your code, use a cell array of strings. Many MATLAB fun...

9 years ago | 0

| accepted

Answered
randomly selecting and deleting rows from a matrix
Your code is likely not doing what you think it is doing. The randperm(427) call gives you a permutation of the numbers 1,2,......

9 years ago | 0

| accepted

Answered
Setting up my structure with a cell array of char vectors.
You are missing a special "feature" of the struct function when one of the inputs is a cell array: https://www.mathworks.com/...

9 years ago | 1

Answered
Write a function that will take two numbers as input arguments and will print a set of concentric squares of stars whenever the row and column are odd.
Here is a starting point: 1) Create a function m-file in your working directory with an appropriate name. E.g., edit myc...

9 years ago | 0

| accepted

Answered
How to make a function that loads its own input variables?
Start with this: doc save doc load Although, you could put everything in a struct and then pass that one struct (inst...

9 years ago | 0

Answered
Extracting values of a matrix in groups of 2 that move along the original matrix
Is this what you want? x(i,1:2) = A(i:i+1);

9 years ago | 0

| accepted

Answered
How to insert elements in a heap
You can clear the variables instead of initializing them to empty doubles. E.g. % ElementsToInsert = []; clear ElementsT...

9 years ago | 1

| accepted

Answered
how to get fprintf to print words with numbers
E.g., assuming provarray is N elements and taxarray is Nx2: m = max(cellfun(@numel,provarray)); for k=1:numel(provarray)...

9 years ago | 0

Answered
codegen error diff(a)~=0
mxArray variables are variables returned from extrinsic functions. There are limitations to what you can do with these variables...

9 years ago | 0

Answered
Please how do i make this while statement check all non-positive integers in the vector x below?
This checks for any non-positive values: while any(x <= 0) Did you also want to check to see if they are integers? E.g.,...

9 years ago | 1

| accepted

Answered
??? Unexpected MATLAB operator (:) when using codegen to generate C code
In place of z(:) maybe try reshape(z,numel(z),1)

9 years ago | 1

Answered
What does it mean when ~ is used as one of the outputs for a function?
It means that the particular output that would ordinarily be returned to a variable at that spot is instead discarded automatica...

9 years ago | 2

| accepted

Answered
Error: Unbalanced or unexpected parenthesis or bracket. But equation looks to be balanced. Help?
You can't have a variable or function name followed immediately by a square bracket like this: slpa[numl(slpa)] maybe yo...

9 years ago | 0

Answered
How to reolve this error? Matrix dimensions should agree..!
Use element-wise operator ./ instead of the matrix operator / r1=3./cos(theta); r2=-4./sin(theta);

9 years ago | 0

Answered
count number of values greater than threshold.
From your description: x = your x-axis values y = your y-axis values (same size as x) threshold = 30; g = x>=1 & x...

9 years ago | 1

Answered
Generating random 3D vectors
E.g., see this discussion: http://www.mathworks.com/matlabcentral/answers/306783-a-matlab-code-of-getting-a-value-uniformly-a...

9 years ago | 0

Answered
How to apply a multivariate function to each element of a vector?
Something like this? a=1; b=2; c=3; X=[-10:1:10]; fun = @(x) testf(a,b,c,x); Y = arrayfun(fun,X);

9 years ago | 0

| accepted

Answered
How can I assign/save a function output to one field of a struct across multiple elements?
[myStruct.outputField] = deal(whatever); Using the brackets on the lhs creates the multiple output requests. The deal on th...

9 years ago | 1

| accepted

Answered
Sorting one matrix with another matrix
[A_sorted,X] = sort(A); Y = repmat(1:size(A,2),size(A,1),1); C = B(sub2ind(size(A),X,Y));

9 years ago | 0

Answered
How can i put a string from an array into the filename?
E.g., assuming you have variables named "name" and "surname" for the first two parts and simply using datestr for the third part...

9 years ago | 1

| accepted

Answered
How does 'break' work?
The "break" statement breaks out of the "innermost" loop that it is inside of. In your code above, it will break out of the for...

9 years ago | 3

| accepted

Answered
How can to concatenate data from each column of a cell array into a row?
Like this? C = your cell array result = mat2cell(cell2mat(cellfun(@transpose,C,'uni',false)),2,ones(1,15600));

9 years ago | 1

| accepted

Answered
Cumulative sum of cell array column
result = cumsum(vertcat(A{:,7})); or result = sum(vertcat(A{:,7})); depending on what you want.

9 years ago | 0

Answered
round random a number
For purely random rounding regardless of the fractional part: x = your number result = round(floor(x)+rand);

9 years ago | 2

| accepted

Answered
Found the answer. Thanks
Do you mean like this? [rows cols] = size(a); nDiags = rows + cols - 1; b=fliplr(a); x = zeros(min(rows,cols),nDia...

9 years ago | 0

Load more