Respondida
matlab error operands to the || and &amp &amp operators must be convertible to logical scalar values
Use P(P< DA.Pl) | (P > DA.Ph) = 0; instead if (P< DA.Pl) | (P > DA.Ph) P=0; end

casi 7 años hace | 0

Respondida
How to select only specific files from a folder that match a list of names stored in a cell and store in a separate folder?
mkdir('new_subfolder'); save('new_subfolder/newfile.mat','C');

casi 7 años hace | 0

Respondida
Unfold 3D Matrix to 2D
Third variant : A = reshape(1:9,3,[])' + cat(3,0,20,30); [m,n,k] = size(A); size_2_3 = [n,k]; xy0 = [2,3]; out = A(:,FunB...

casi 7 años hace | 0

Respondida
How to select only specific files from a folder that match a list of names stored in a cell and store in a separate folder?
% Let A - list of 400 names as cell-array(400 x 1) files = string(A) + '.mat'; n = numel(files); C = struct; for ii = 1:n ...

casi 7 años hace | 0

| aceptada

Respondida
Find columns of a Matrix (n x m) that fit best to a Vector (n x 1)
% Let A - your array (24 x 365) % B - your forecast vector (24 x 1) m = 6; ii = sqrt(sum((A - B).^2)); [~,ij] = mink(ii,m)...

casi 7 años hace | 1

Respondida
how to select highest three maximum values from each row of an matrix
A=rand(3,8); B = sort(A,2,'descend'); out = B(:,1:3);

casi 7 años hace | 1

| aceptada

Respondida
Adding Value in the array with proper indexing
ME=4; E=rand(1,ME); [ES,ii]=sort(E,'descend'); Ls=length(ES); Hl=(Ls/2); maxval=ES(1:Hl); mxii = ii(1:Hl); minval=ES(Hl+1...

casi 7 años hace | 0

| aceptada

Respondida
Unfold 3D Matrix to 2D
[m,n,k] = size(A); B = ones(k,n); [y,x] = find(B); DT = delaunayTriangulation(x,y); C = convexHull(DT); [yy,xx] = ind2sub([...

casi 7 años hace | 1

Respondida
Adding Value in the array with proper indexing
ME=4; E=rand(1,ME); [ES,ii]=sort(E,'descend'); Ls=length(ES); Hl=(Ls/2); maxval=ES(1:Hl); mxii = ii(1:Hl); minval=ES(Hl+1...

casi 7 años hace | 0

Respondida
Attempting to automate the importing of text file data
%Let directory 'data' have your files: 40_8deg_HL_Both.txt and 40_4deg_HL_Both.txt n = dir('path_to_data/data/*Both.txt'); m =...

casi 7 años hace | 0

| aceptada

Respondida
How can I convert cell contents to a matrix?
T = readtable('40_8deg_HL_Both.txt','ReadVariableNames',false,... 'Format','%{yyyyMMdd hh:mm:ss.SSS}D %f %f %f %f %f %...

casi 7 años hace | 1

| aceptada

Respondida
How can i store values calculated in my loop
X = [9 20 15 9 10 5;5 20 5 20 15 3;15 29 39 49 5 10]; [rows, columns]=size(X); for r=1:columns for k=1:3 if X(k,...

casi 7 años hace | 1

Respondida
count the quantity of prime number before my number
x=input('Input a positive integer, or 0 to quit: '); z = [2,3:2:x]; y= mod(z(:),z(:)'); out = z(all(tril(y) + triu(ones(siz...

casi 7 años hace | 0

Respondida
How to create a matrix using conditional statements in a loop based in another matrix
H = all(Comb,2).*sum(Comb,2);

casi 7 años hace | 1

| aceptada

Respondida
Find the first element that satisfy a condition in a vector
function [summa, index] = max_sum(A,n) B = movsum(A(:),[0 n-1]); summa = max(B); index = find(summa == B); end ...

casi 7 años hace | 0

| aceptada

Respondida
How to plot matrix inside for loop ?
A = [0 3/10;3/5 0]; u = [0.3 ;0.8]; p = [0;0]; P = zeros(2,50); for n = 1:50 p = A*p + u; P(:,n) = p; end plo...

casi 7 años hace | 1

Respondida
How to group an array and then replace each group with different numbers?
B = A; B(A==0) = repelem(C,diff(reshape(find(diff([1,A,1]) ~= 0),2,[])));

casi 7 años hace | 1

| aceptada

Respondida
Center of gravity between 2 points
x = [1 3]; y = [2 5]; v = [10 20]; xc = sum(v.*x)/sum(v); yc = sum(v.*y)/sum(v);

casi 7 años hace | 0

| aceptada

Respondida
How to replace some values in an array with zero and some with values from another array?
A = [2 4 0 0 5 3 0 2 1 0 2]; B = [1 1 0 1]; A1 = ~A; C = double(A1); C(A1) = B;

casi 7 años hace | 0

Respondida
Combining vectors [1 2 3 4 5] and [2 3 4 1 5] to [12 23 34 41 55]
A = [1 200 3 4 5]; B = [23 3 445 10 54]; out = str2double(string(A)+B); or out = A.*10.^(floor(log10(B))+1) + B;

casi 7 años hace | 0

Respondida
Vectorize a for loop
Solution for attached data: [~,sheets] = xlsfinfo('MapList.xlsx'); n = numel(sheets); ml = cell(n,1); for ii = 1:n ml{i...

casi 7 años hace | 0

Respondida
How to make the main diagonal and the diagonal above and below the main diagonal equal to -2 and 1 respectively
A = gallery('tridiag',100,-1,2,-1); or n = 100; A = spdiags(ones(n,1)*[-1 2 -1],-1:1,n,n);

casi 7 años hace | 1

Respondida
Vectorize a for loop
Please attach your data (bimage,map.xlsx - small example) as mat-file and xlsx-file. ml = zeros(200,2,66); for ii = 1:size(ml,...

casi 7 años hace | 0

Respondida
how to make a column vector with evenly spaced entries with different coefficients
k = -4:-1; y = 3; n = numel(k); y = [zeros(n-1,n);y*k(:)']; ycoeff = y(:); or k = -4:-1; y = 3; n = numel(k); ycoe...

casi 7 años hace | 0

| aceptada

Respondida
Convert an array of numbers into letters using logical indexing
v = [0, 5:.5:10]'; S = string(cellstr(('F':-1:'A')')); K = S(4:6)' + {'-','','+'}'; K = [S(1:3);K(1:end-1)']; out = discret...

casi 7 años hace | 0

Respondida
How do I compute 3 minute moving average in timeseries?
Let ts - your timeseries object. k = 3*60/2; % the number of elements corresponding to three minutes in your case ts.Data(:,2)...

casi 7 años hace | 0

Respondida
I have a huge matrix to A to solve for Ax=B. There are some rows with zero elements in A and I want to modify the diagonal for these rows. So how can I fast find these rows with all zero elements? for loop is rather slow.
"How to set diagonal as 1 for the row with all zero elements?" A = A + diag(~diag(A)); or n = all(A==0,2); A = A + diag(n); ...

casi 7 años hace | 0

Respondida
Convert hourly to daily data
T = readtable('IT_GR_data.csv','ReadV',1); T.Properties.VariableNames{1} = 'Date'; TT = table2timetable(T,'RowTime','Date');...

casi 7 años hace | 1

| aceptada

Respondida
How to solve this loop equation
data = readtable('data.xlsx','ReadV',0); data.Properties.VariableNames = {'a','b'}; m = 0:.01:1; [ii,idx] = ndgrid(m,1:heig...

casi 7 años hace | 1

| aceptada

Respondida
Values of vectors in matrix (changes in time)
t =0:pi/20:4*pi; x =reshape(cos((1:4)'*t),2,2,[]);

casi 7 años hace | 1

Cargar más