Answered
For loop to create a new matrix taking a cluster of columns from existing matrix
The MATLAB approach using reshape, permute, and sum: inp = randi([1,20],1300,36) out = sum(permute(reshape(inp,1300,4,[]),[1,3...

5 years ago | 1

Answered
How to skip lines after the header line when using readtable
type test.csv opts = detectImportOptions('test.csv'); opts.DataLines = 3; opts.VariableNamesLine = 1; T = readtable('test.cs...

5 years ago | 6

| accepted

Answered
Add names to table variables from a large cell
% Fake data: V = {[1,3,4],[4,7,8],[1,2]}; A = randi(9,5,4); % Create table: F = @(n)sprintf("{%s}",join(string(n),",")); T ...

5 years ago | 0

| accepted

Answered
Why readtable() function cannot read an xlsx file properly?
This is caused by the different row lengths in sheet 3: the shortest row has just 7 non-blank cells, the longest row has 147 non...

5 years ago | 1

| accepted

Answered
how to separate string matrix by zeros
This would have been easier if you had imported the data as numeric, rather than as string. Rather than relying on low-level lo...

5 years ago | 0

| accepted

Answered
Create table from structure - alignment
Simpler: mom.a = 1; mom.b = 2; mom.veryLongName = 3; hdr = {'Moment'; 'Value'}; tmp = [fieldnames(mom),struct2cell(mom)].';...

5 years ago | 0

| accepted

Answered
Rearranging array based on number of steps.
https://www.mathworks.com/help/matlab/ref/reshape.html https://www.mathworks.com/help/matlab/ref/permute.html A = 1:24; N = 3...

5 years ago | 1

| accepted

Answered
How to select a specific element in a table using variables corresponding to table headers
How to select data from a table is explained here: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.htm...

5 years ago | 0

| accepted

Answered
json char with too many decimals, need removal
str = '{"hund": 0.3253533250000000000000000000000000, "kat": "dfsdfs", "baenkebider": 0.002021203321320000000000000000000000}'; ...

5 years ago | 0

| accepted

Answered
How to replace cell values with consecutive values related to their index
Simpler: C = {cell(1,1),cell(1,5),cell(1,3)} N = cellfun(@numel,C); D = mat2cell(1:sum(N),1,N)

5 years ago | 1

Answered
How can I remove . and ..
Replace {sad([sad.isdir]).name} with setdiff({sad([sad.isdir]).name},{'..','.'})

5 years ago | 0

| accepted

Answered
Using different functions in a loop
Convert strings-of-function-names to function handles (which they should be anyway): C = {'sin','sqrt','abs'}; C = cellfun(@st...

5 years ago | 0

| accepted

Answered
How to convert a long string into desired length variables or cells?
S = "ea3672f1a9012345"; V1 = sscanf(S,'%1x') V2 = sscanf(S,'%8x')

5 years ago | 1

| accepted

Answered
How can I find indices?
A = [1,2,3,3,1,1,2,1;1,1,1,2,2,3,2,3] B = [2,1;1,3] [~,X] = ismember(B.',A.','rows')

5 years ago | 0

| accepted

Answered
Reading Text file and converting values to variables (*not in matrix form*)
P = 'absolute or relative path to where the file is saved'; S = fileread(fullfile(P,'output.txt')); F = @(t)sscanf(regexprep(S...

5 years ago | 2

| accepted

Answered
How can i name the column on a table ?
You created a table with one variable and one row, and that variable contains a large numeric matrix. This is not useful for you...

5 years ago | 0

| accepted

Answered
How to assign the values to a matrix?
https://www.mathworks.com/help/matlab/ref/sub2ind.html B = [1,9,12,31]; C = [1,4;3,6;5,2;6,3] A = zeros(6,6); % assign those...

5 years ago | 0

| accepted

Answered
Reading CSV as Structure Array
T = readtable('Test_Expression.csv', 'Decimal',',', 'Delimiter',';') S = struct('gene',{T.gene}, 'value',T.value) S.rawValue =...

5 years ago | 0

| accepted

Answered
element wise operation column matrix
T = [20;27;29;33;40]; A = T - T(1) B = [0;diff(T)]

5 years ago | 0

Answered
Extract arrays from cell with order in a for loop
B = A; for k = 1:numel(A) array_to_crop = A{k}; array_cropped = array_to_crop(5:22,1); %Cropping selected array ...

5 years ago | 0

| accepted

Answered
How to create corresponding equation in a column based on the value of previous column? (Similar to drag in Excel)
The MATLAB approach would be to use logical indexing: https://www.mathworks.com/help/matlab/math/array-indexing.html For examp...

5 years ago | 0

| accepted

Answered
Read all .csv file in Folder , rearrange and write in one .csv file
P = 'absolute or relative path to where the files are saved'; N = 150; C1 = cell(1,N); C2 = cell(1,N); for k = 1:N F = ...

5 years ago | 0

Answered
Trying to find row numbers from array inside cell array entry
T = readtable('Text1 1-10.txt', 'Delimiter','\t') https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html...

5 years ago | 0

| accepted

Answered
Changing the variable names for multiple tables within a loop that imports the data
Using eval is a misdirection that forces you into writing slow, inefficient, complex code: https://www.mathworks.com/matlabcent...

5 years ago | 0

| accepted

Answered
Second derivative of a function handle
Tip for beginners: whenever you use EVAL you are doing something wrong. With symbolic variables you do not need to define anony...

5 years ago | 0

| accepted

Answered
The logical indices contain a true value outside of the array bounds
As the error states, your logical indexing includes a TRUE value outside the size of that array. Compare: V = randi(9,1,3) X =...

5 years ago | 1

Answered
How to create empty indexes when not available?
data = [2,3,4,5,3,2,4,5]; x = 5; n = 10; p = 2; window = data(max(1,x-n):min(end,x+p)) Are the NaNs really required?

5 years ago | 0

| accepted

Answered
I need help preallocating an array of position vectors
Use a cell array: tmpout = cell(1,stack_size(4)) for frame_no = 1:stack_size(4) .. tmpout{frame_no} = pos; end mat...

5 years ago | 1

| accepted

Answered
Naming new directories sequentially
N = number of directories P = 'absolute/relative path to the parent directory'; for k = 1:N D = sprintf('Prefix_%03d',k);...

5 years ago | 0

| accepted

Answered
accessing multiple individual struct field values
S(1).data = [1;2;3]; S(2).data = [4;5;6]; S(3).data = [7;8;9]; n = 2; V = arrayfun(@(s)s.data(n),S) or (assuming that each ...

5 years ago | 0

Load more