Answered
need help vectorizing a complicated loop
If you change the size of the s, c and y vectors to 1x1x2000 then this is easy. For MATLAB version R2016b or later: s = rand(1,...

7 years ago | 0

| accepted

Answered
How to extract rows the first 4, skip 21 rows, and extract the next 4 rows
Where M is your matrix, adjust the constants to suit your needs: vec = 1+mod(1:size(M,1),21); idx = 1<=vec & vec<=4; out = M(...

7 years ago | 0

Answered
read files in a directory
This will read the data from one file (attached): [fid,msg] = fopen('sr36161v4.0.txt','rt'); assert(fid>=3,msg) % Preamble da...

7 years ago | 0

| accepted

Answered
How can I automatize the selection of multiple '.zip' files?
As the MATLAB documentation https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html explains, you...

7 years ago | 0

| accepted

Answered
how to read data from characters?
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html D = 'path of the directory where those fil...

7 years ago | 0

| accepted

Answered
fast interp on 1 dimension of 3d matrix
Use interp3 or interpn: >> A = randi(9,5,7,3) A(:,:,1) = 3 3 5 3 8 1 2 8 7 3 4 9 9 2 3 5...

7 years ago | 0

| accepted

Answered
How to write a cell array of mixed strings and integers into a text file?
Where C is your cell array: C = {'GALK1',1;'ERCC2',1;'PGD',1;'PLK',1;0,0;0,0;0,0;0,0;0,0}; D = cellfun(@num2str,C,'uni',0).'; ...

7 years ago | 1

| accepted

Answered
How can I convert a matrix of numbers into a cell array of names?
It is simpler and much more effiicient to just use indexing: >> M = reshape(randperm(10),5,2) M = 7 10 5 4 ...

7 years ago | 0

Answered
Is there a quick and easy way to insert/delete values into the middle or beginning of a cell array and/or a numerical array
Just use indexing: >> V = randperm(9) V = 9 5 7 3 4 6 8 2 1 >> idx = 3; >> val = 0; >> V = [V(1:idx),va...

7 years ago | 0

| accepted

Answered
Hi guys how can swap the max value and min value for a matrix ?
>> A = randperm(9) A = 5 6 1 3 7 8 4 9 2 >> [~,idx] = max(A(:)); >> [~,idn] = min(A(:)); >> A([idx,idn])...

7 years ago | 0

Answered
Assigning blank cell array confuses Matlab with data type
x_cell = {single([])}; % assign. Note that your code expands the numeric array on each iteration, which is inefficient. It is r...

7 years ago | 1

| accepted

Answered
I would like to write a computation that will take a vector of 1xN length and then add adjacent matrix values .
Where V is your vector (containing an even number of elements): V(1:2:end)+V(2:2:end)

7 years ago | 0

| accepted

Answered
How to acieve a scatter plot like this.
One simple option is to use pcolor: >> M = randi([-3,6],5,7); >> M([3,4,5,9,10,15]) = NaN; >> pcolor(1:7,1:5,M) You ca...

7 years ago | 1

Answered
functions with different conditions
>> f = @(x) x.^2.*(x>1) + x.^4.*(x<=1); >> integral(f,0,2) ans = 2.5333

7 years ago | 2

| accepted

Answered
Is it possible to make an if-statement with multiple conditions (a vector of numbers)?
Use any: if any(B(1,i)==65:90) Or ismember: if ismember(B(1,i),65:90)

7 years ago | 0

| accepted

Answered
How can I merge many rows of different lengths into a matrix?
>> C = {1:2,3:7,1:10}; >> L = cellfun('length',C); >> M = zeros(numel(C),max(L)); >> for k = 1:numel(C), M(k,1:L(k)) = C{k}; ...

7 years ago | 0

| accepted

Answered
'Array indices must be positive integers or logical values' error for directory use
"I have been told by my lecturer that continuously using the csvread(files(i).name) function will slow down my code as it has to...

7 years ago | 0

| accepted

Answered
Non-singleton dimensions of the two input arrays must match each other using bsxfun
The problem lies in the last dimension (here I marked the first three dimensions with r,c,p because their actual numeric values ...

7 years ago | 0

| accepted

Answered
How to compare 5 cell arrays and get their contents in one cell array?
Use ismember in a loop: C0 = {'A';'B';'C';'D';'F'}; % your 600x1 cell array. C1 = {'A',1;'C',123;'X',0}; C2 = {'B',21;'D',222...

7 years ago | 2

| accepted

Answered
if + for loops vs while loop. Same good different results
Work backwards from the end, and look at where the time / T value last changes. They are not the same. The location of the the i...

7 years ago | 1

| accepted

Answered
Vector multiplication in equation
Use parentheses to group the denominator together, and use the correct division operator: x=sqrt((a*b*c)./(d*e*f)) And tested:...

7 years ago | 3

Answered
How to get the original Image matrix from the Integral Image of a N*N matrix?
A simple solution based on the explanation given on the integralImage help page: >> II = [0,0,0,0,0;0,1,3,6,10;0,6,14,24,36;0,1...

7 years ago | 1

| accepted

Answered
how to sum the elements of the same row in a cell array?
>> C = {'A','hello';'B','live';'C','cat';'A','world';'B','fast'}‡ C = 'A' 'hello' 'B' 'live' 'C' 'cat'...

7 years ago | 0

| accepted

Answered
Conversion of a string back to an existing vector name for assigning data
As Guillaume and I wrote in comments to your question, the best solution is to avoid this situation entirely. If you find yourse...

7 years ago | 1

Answered
File formatting in Matlab
>> M = dlmread('temp0.txt'); >> M = M.'; >> dlmwrite('temp1.txt',M(:)) The test files are attached.

7 years ago | 0

Answered
Sortrows alternative / matrix sorting
function [A,B] = mysortdata(A,B) M = qsRecFun([A;B]); A = M(1,:); B = M(2,:); end function M = qsRecFun(M) N = size(M,2); ...

7 years ago | 1

| accepted

Answered
How can I create a new matrix by using existing values in a column?
Simpler and much more efficient to use toeplitz: >> B = [0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020]; >> C = zeros(...

7 years ago | 2

| accepted

Answered
Compute differences bewteen vectors in a matrix
This is easy to achieve with basic indexing and an anonymous function: >> A = randi(9,5,7) A = 4 4 5 9 4 7 1 ...

7 years ago | 0

| accepted

Answered
Question Regarding Sorting of the elements
>> X1 = [ 4 2 6]; >> V1 = [ 5 9 1]; >> X2 = [ 1 5 3]; >> V2 = [ 0 0 0]; >> X(X1) = V1; >> X(X2) = V2 X = 0 9 0 5...

7 years ago | 0

Answered
How to sort a matrix with the second row depending on the sorting of the first row?
One easy way to obtain indices from any sorting algorithm is to "hang" some indices onto the data before sorting, and apply exac...

7 years ago | 1

| accepted

Load more