Answered
Ranking row values of matrix without adjustment
for a vector: V = [ 7 6 2 9 2] [~,r] = sort(V) rankV(r) = 1:numel(V) for a matrix, you can loop over the columns ...

9 years ago | 0

Answered
Round floating number without zeros
Use %f as a format holder rather than %d, and specify the number of decimals, like this x = 1.320001 sprintf('%.2f',x)

9 years ago | 0

| accepted

Answered
Stretch matrix without increasing the combined sum of all values
Something along these lines? A = ones(10,1) dN = 1 ; % stretch A with dN elements NA = numel(A) ; B = interp1(...

9 years ago | 1

Answered
I need to plot a sine wave
This is the general formula of a sine wave. If leave it to you to fill in the numbers. y = Amplitude * sin(2*pi*f*t + phase...

9 years ago | 0

Answered
averaging a group of 19 rows and columns
Let X be your matrix X = rand(10,3) ; % example N = 3 ; % number of rows to average niX = size(X,1) ; % number ...

9 years ago | 0

Answered
Interpolate matrix to same size matrix
You could simply replace the lower values with the original ones? A = ... % original matrix with zeros B = ... smoothed ...

9 years ago | 0

Answered
How to calculate the correlation between 4 variables in a matrix
See the documentation on CORR and PARTIALCORR, both in the Statistics Toolbox: <https://uk.mathworks.com/help/stats/corr.html...

9 years ago | 0

Answered
Splitting a vector into unequal sections with values greater than or equal to 2 for at-least next 5 cells
First create a vector that will be true when an element x of A and the next N elements are larger than a values V N = 5 ; V...

9 years ago | 0

| accepted

Answered
check the return code of fprintf...If disk became full while writing..?
count = fprintf(...) Count will be less then expected when disk is full.

9 years ago | 0

Answered
Create keyboard listener to interrupt a running function
You might be interested in my File Exchange contribution STOPLOOP or GETKEY: <https://uk.mathworks.com/matlabcentral/fileexchan...

9 years ago | 0

| accepted

Answered
how to create array as i describe down?
x = 17 a0 = (fix(x/10)+1)*10 v = [x a0:10:120]

9 years ago | 2

| accepted

Answered
Assign value to field of nested structure in a structure array
[person(1:4).FamilyInfo] = deal(struct('NumerOfsiblings',3)) ;

9 years ago | 1

Answered
can we find the original matrix back from the modified matrix whose rows were initially swapped .
So you know B and the vector v that contains the two rows where swapped to create A. Then it is easy: A = magic(5) v = [...

9 years ago | 0

Answered
How to optimize for loop
I think I am missing something. Why runs j from 2 instead of 1? Is value a constant? If so, this would suffice: newimg = ...

9 years ago | 0

Answered
how to get n by n matrix from a given matrix?
No need for special toolbox functions as clever indexing suffices. This two-liner will work for any 2D array A, and any value o...

9 years ago | 0

Answered
Sorting element pairs by differences?
Take a look at NCHOOSEK, ABS, DIFF, and SORT: * with X = nchoosek(values,2) you can get all the 6 different combinations * u...

9 years ago | 1

Answered
How Store a set of Matrices independently after each iteration is done in a for loop.
Do not create names like MN1, MN2 etc. What if you have a 1000 matrices likes this? They are all related,, but have different va...

9 years ago | 1

Answered
Creating a random matrix with conditions without using iteration
A = [1 5 3 2 4] A(A>3) = 0 % all at once, the way to go!! B = [1 5 3 2 4] for k=1:numel(B), % iteration over each...

9 years ago | 0

Answered
Convert a string of numbers to a number.
Look mammy, no hands! S = '6387' N1 = sscanf(S,'%d') N2 = (S - '0') * (10.^(numel(S)-1:-1:0)).' % N3 = ...

9 years ago | 2

Answered
Wilcoxon rank sum test
The p-value is derived from comparing a test-statistic (in this case a z-value obtained by summing ranks) to a theoretical distr...

9 years ago | 1

Answered
Storing User Input as Vector, Stopping on 0 value for calculation.
The code look ok, but what I really like is that you have commented it quite well. *Keep that up!!!* Maintaining and debugging c...

9 years ago | 0

Answered
how to compare multiple mxn arrays to find a common point?
Assuming that each column of Z represents a point in 2D space, you can transpose the matrices and use intersect with the 'rows' ...

9 years ago | 1

Solved


Is my wife right?
Regardless of input, output the string 'yes'.

9 years ago

Answered
how to build sequential cell rows
Arrayfun seems easier than the cellfun/mat2cell approach: B = [23 25 24 28 30 32]; A = arrayfun(@(k) B(k...

9 years ago | 0

Answered
How to cut an array and reshape it while keeping the content in order?
This is easy using a cell array as an intermediate step T = repmat(1:12,3,1) % example array S = size(T) n =...

9 years ago | 0

Answered
make a legend display a variable input
% an example x = -10:10 ; color = {'r','g','b','k'} ; hold on ; for k=1:4, y = (k-2) * x + k ; ph(k)...

9 years ago | 1

Answered
How can I extract the upper triangular part of a matrix and set only the off-diagonal values to pi?
Your statements make no sense: ones(1,1) wil give you the scalar 1 ... I think you are after something like this: N = 3 ...

9 years ago | 2

| accepted

Answered
how to extract the names of all the files with an specific extension content in different directories and omit the name if is repeated?
imageDirs = {dir1 dir2 dir3} ; for k = 1:numel(imageDirs) flames = dir(fullfile(imageDirs{k}, '*.jpg')) ; % fullfile ...

9 years ago | 0

| accepted

Load more