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

10 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);

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

10 years ago | 0

Answered
Output Argument Error - How to Define The Output Argument for a Function
Don't have the return variable name the same as the function name. Use a different name for the return variable (e.g., "result")...

10 years ago | 0

Answered
Change Values of array to zero
The numbers are very small but not exactly 0. They just print as 0 with the display format used. To get them to exactly 0 you c...

10 years ago | 0

| accepted

Answered
how to vectorize this loop
cumavg = cumsum(v)./(1:numel(v)); mark = find(cumavg<=(avg-0.01),1,'last');

10 years ago | 0

| accepted

Answered
libcpmt.lib(xthrow.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1800' in nms_gpu_mex.o
_MSC_VER is a value corresponding to the version of the Microsoft compiler that is being used. The 1600 is for Visual Studio 20...

10 years ago | 0

Answered
Assign values to different ranges of columns in rows in a 2Dmatrix
It is not entirely clear from your description what you want. If you want the entire column set to a certain value where the "i...

10 years ago | 1

| accepted

Answered
Parse error at Function:usage might be invalid syntax
Very hard to read your pic of the code (in the future, post the actual code and not a picture), but from the looks of it you hav...

10 years ago | 0

Answered
Matrix indexing problem, column-major
if X(xr,xc) < (xr*xc) % <-- changed X to X(xr,xc) A = [A;[xr,xc]]; % <-- changed [xr;xc] to [x...

10 years ago | 1

| accepted

Answered
how to convert a matrix into one single column vector
B = reshape(A',[],1);

10 years ago | 3

| accepted

Answered
Looping with two vectors ?
It is unclear why you have a loop at all, but maybe this is what you want? for ii = 3002:10001 Or maybe you just need to...

10 years ago | 1

Answered
Creating a matrix that calculates inverse and determinants without using the det and inv commands
Create a file in your working directory called invanddet2by2.m, e.g. edit invanddet2by2.m In that file, put the followin...

10 years ago | 0

| accepted

Answered
Error using / Matrix dimensions must agree.
Use element-wise operators .* and ./ instead of matrix operators * and / y=abs(1/complex(0,2)*( 1./(1-exp(complex(0,-Ts*w))...

10 years ago | 1

Answered
Unable to compile using "mex fmpc_sim.c libmwblas.lib libmwlapack.lib" undefined reference to '_dgemm_'
Looks like the source code you are using was intended for UNIX machines. In particular these errors: c:\users\n\appdata\loc...

10 years ago | 2

Answered
Write a function that takes an input argument n, checks whether or not n is positive, and then provides the sum: 1 + √2/2! + √3/3! + ⋯ + √n/n!.
1) Create a function file called myfunction.m in your working directory. E.g., edit myfunction.m 2) Put the following co...

10 years ago | 1

Answered
Write a function that receives an input argument of a number of kilometers (km) and will output the conversions into both miles (mi) and US nautical miles (n.m.). Use the conversions: 1 km = 0.621 mi and 1 km = 0.540 n.m.
1) Create a function file called myconversion.m in your working directory. E.g., edit myconversion.m 2) Put the follow...

10 years ago | 0

Answered
How do I combine data from two structures?
E.g., with a loop using dynamic field names: f = fieldnames(A); for k=1:numel(f) A.(f{k}) = [A.(f{k});B.(f{k})]; ...

10 years ago | 2

Answered
Why is it saying that I am exceeding the matrix dimensions for the sum_xy when x(2) is clearly a part of the vector that I give
You want to change your while test to this: while i < n because the next line increments i. If you allow i to be n afte...

10 years ago | 1

Answered
Assign vectors (returned from a function) to the colums of a matrix
If you can modify the source code of myfun, you could have it detect the number of requested outputs. If the number is greater ...

10 years ago | 2

| accepted

Answered
How do I assign a text to a numerical value for an array inside of a for loop?
If UPDRS1997 is just a scalar you could do this: conditions = {'normal','slight','mild','moderate','severe'}; x = condit...

10 years ago | 0

Answered
Why does Matlab transpose hdf5 data?
In the following link: <https://support.hdfgroup.org/HDF5/doc/H5.format.html#LayoutMessage> I read the following under Dat...

10 years ago | 0

| accepted

Answered
WHILE loop with a condition on a vector?
Like this? while any(~(abs(vector_a) <= 0.00001)) % do stuff end Or this (but will not get the same result if ...

10 years ago | 1

| accepted

Answered
load and if conditions
Maybe just get rid of that for-loop (assuming _pick_year_ is one of the variables that gets loaded). E.g., pick_year = inpu...

10 years ago | 0

Answered
For some reason every time I try to test my forward elimination function there is an error in the sum part, I cannot figure out why or what else I need to ad
Looks like you are incrementing the i index variable twice ... once as a for-loop index and once explicitly: for i = 1:n ...

10 years ago | 0

| accepted

Answered
Why can't I mex cpp with matlab?
You should not redefine mwSize and mwIndex in your code ... you should only define them if they are not already defined. One wa...

10 years ago | 0

Answered
What is the final value of this variable when executed in MATLAB?
Just take each term that gets added to final_value in the for-loop and add up what happens for each iteration. E.g., the term th...

10 years ago | 0

| accepted

Answered
difference in brackets (, [ or no brackets?
0:2:10 produces a row vector of the numbers 0,2,4,6,8,10. In the [0:2:10] and (0:2:10) versions, the [ ] and ( ) are simply r...

10 years ago | 4

| accepted

Answered
Insert first value in vector into next 11 lines using an If loop
This follows your specified pattern using the repmat function: T = your 8754x1 temp data vector Tresult = reshape(repmat...

10 years ago | 0

| accepted

Answered
How can I access a field in a structure array using a cell array containing strings corresponding to these fields using a for cycle?
You almost had the syntax correct. Use "dynamic field names" by enclosing the field name variable (in this case B{i}) inside pa...

10 years ago | 0

| accepted

Load more