Answered
Deleting words [ ] and 'neutral'
*EDIT* out = result(all(~cellfun(@(x)isempty(x) | strcmp(x,'neutral'),result),2),:); or out = result(~any(cellfun(@...

14 years ago | 0

| accepted

Answered
Count the number of trend changes in a vector.
*EDIT* a = diff(vec(:)); out = nnz(unique(cumsum([true;diff(a)~=0]).*(a~=0)));

14 years ago | 0

| accepted

Answered
Add date variable into Xlsread Syntax?? Needs Help!!
*case 1* in case: your files from |199001.xlsx| to |199108.xlsx| b = diff(datevec({'199001';'199108'},'yyyymm')); mn...

14 years ago | 0

| accepted

Answered
create point betweem two points
out = ([10,15]-[2,5])*(2*rand-1)+[2,5]

14 years ago | 0

Answered
position of maximum in matrix
M - matrix, please read <http://www.mathworks.com/help/techdoc/ref/max.html here>. [value,index] = max(M);

14 years ago | 0

Answered
How to plot consistent data?
T = [9 8 7 8 9 7 6 5 4 5 6 7 8 9 10 11 12 13]; a = [true,diff(T)>=0]; a(strfind(a,[0 1])) = true; n = 10; ii = fin...

14 years ago | 0

| accepted

Answered
deleting an element from a Matrix without changing its dimensions?
variant for double array: instead of an empty element - nan A = [ 1 2 3; 4 5 6; 7 8 9]; A(2,2) = nan; variant for cel...

14 years ago | 1

| accepted

Answered
if Statement for text files
[S,S] = weekday(now + (0:6),'long') i1 = strncmp(out,'REST',4) idx = i1 | ismember(out,cellstr(upper(S))); I = cumsum...

14 years ago | 0

Answered
Bit setting a binary number
a = dec2bin(3124) a(end - (5:-1:0)) = '100000'

14 years ago | 0

| accepted

Answered
reshaping 2 vectors of dates
variant use within |regexprep| D = regexprep(D,'[a-z\-]',''); DD = regexprep(DD,'[ .a-zE]','');

14 years ago | 1

| accepted

Answered
Detecting a particular word in a cell vector
eg A = {'MAR' ' POPSIZE' 'OTHTOTAL' ' CONIZE' ' POPIZE' 'MAR' ' POPULAR...

14 years ago | 0

| accepted

Answered
erasing all the rows that begin with NaN
just out = A(~cellfun(@(x)all(isnan(x)),A(:,1)),:)

14 years ago | 0

| accepted

Answered
Vectorize double loops with constraints on the indexes
other variant eg: % input data k = 10; d = 40; lambda = 1; z = randi(12,d+2,1); % solution ...

14 years ago | 1

Answered
Convert a vector to a scalar
data not sufficient, but try this is code: ISAT = arrayfun(@(x)q.*quad(@Integral, 0, x, 1),t);

14 years ago | 0

Answered
Help with vectorizing Diag command
[m,n] = size(oldMat); idx = permute(repmat(logical(eye(n)),[1,1,m]),[3 2 1]); nM = idx+0; nM(idx)=oldMat;

14 years ago | 0

Answered
Creating a matrix using for loop.
b = [zeros(1,numel(a));tril(toeplitz(a))]; or b = toeplitz([0;a],zeros(1,numel(a))); or a1 = [0;a]; i1 = (...

14 years ago | 1

Answered
loop for clock in MATLAB
try datestr(datenum(0,0,0,12,(0:15:15*9)',0),'HH:MM') ADD after Samer's answer m=15; id = [6 16]; time1 = ce...

14 years ago | 0

| accepted

Answered
Creating vector of all numbers in a cell array.
nums = cat(2,A{:}); general case: let A = arrayfun(@(x)randi(randi([3 40]),randi([6 20],1,2)),zeros(3,4),'un',0); ...

14 years ago | 1

Answered
verification of the intepretation of a simple code that contains "isequalwithequalnans"
isequalwithequalnans(a,b) | isequalwithequalnans(a,c)

14 years ago | 0

| accepted

Answered
random normal distributed numbers
BUT this is NOT normal distribution k = randn(100,1); a=1.4; b=1.6; m = min(k); out = (k - m)*(b - a)/(max(k)-m...

14 years ago | 0

Answered
Replace Nan with previous numbers
t = ~isnan(data); a = data(t); out = a(cumsum(t)); ADD on Aggelos's comment t = ~isnan(data); idx = cumsum(t)...

14 years ago | 2

| accepted

Answered
how to randomly vary 2 numbers?
eg A = (rand(5) > .5) + 0; A(~A) = -1; or A = 2*randi([0 1],30,1) - 1;

14 years ago | 1

Answered
Filter/identify characters within a cell array
try this is code value1 = cellfun(@(x)x(1),cell_array,'un',0); [a,b,b] = unique(value1); i1 = histc(b,1:max(b)); t...

14 years ago | 0

| accepted

Answered
calculate monthly averages of time series
[a,b,b] = unique(DateVec(:,1:2),'rows'); out = [a,accumarray(b,Data,[],@mean)]; %EDIT row or [a1,b1,b1] = unique(Da...

14 years ago | 1

| accepted

Answered
comparing matices that contain numbers and NaNs
variant of comparison cell arrays (edit) A = {... [84] [ 93] [ 109] [99] [NaN] [ 62] [29] [123...

14 years ago | 0

| accepted

Answered
Assigning input string as variable name
x = input('Enter the name of the new variable: ','s'); eval([x,'=0:4;']);

14 years ago | 2

Answered
Detecting and eliminating numbers from a cell matrix that contains NaNs and string characters
A = {[ NaN] [ NaN] [ NaN] [ NaN] [ NaN] [ NaN] 'England' ...

14 years ago | 1

| accepted

Answered
Calculating combinations of dates
EDIT [Y M D] = datevec(jji,'dd/mm/yyyy'); ED = eomday(Y, M); v = cell2mat(values); n = numel(v); out = sum([D, ...

14 years ago | 0

| accepted

Answered
vector index of consecutive gap (NaN) lengths?
A = [2 4 NaN 7 9 NaN NaN NaN 32 NaN NaN 8]; a = isnan(A); t1 = find([true, diff(a)~=0]); N = diff(t1); out = zeros...

14 years ago | 1

Answered
select some compenent of vector
V1 = V(4 + (0:3));

14 years ago | 0

Load more