Answered
How to include 'end' in a varibable to extract a subset of the original vector ?
"... if i want to define range before the definictiion of the vector..." You could use an anonymous function: rng = @(v)v(1:en...

5 years ago | 2

| accepted

Answered
Convert values in the cell to array using cell2mat
The robust approach: out = horzcat(output1{:})

5 years ago | 0

| accepted

Answered
How to store matrices in a cell from a loop?
Rather than lots of separate variables, use a comma-separated list to store the function outputs: https://www.mathworks.com/hel...

5 years ago | 0

| accepted

Answered
Function output produces double array while only a single value is expected
I would avoid all of those superfluous and inefficient type conversions and messing around with indexing into character arrays. ...

5 years ago | 1

| accepted

Answered
Read set of .dat files in for loop
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html P = 'absolute or relative path to where th...

5 years ago | 0

| accepted

Answered
How to count alternating ones and zeros in a matrix
v =[ 0 0 0 0 0 0; ... 1 1 0 1 1 0; ... 1 0 1 0 1 0; ... ...

5 years ago | 0

Answered
Round the elements column of the matrix to the same digit than it is in the other column
S = 2; A = 32*rand(5,7)-13 round(A(:,5),S,'significant') % for comparison P = S-1-floor(log10(abs(A(:,5)))); B = round(A.*10...

5 years ago | 0

Answered
how to combine datetime array with cell array for export?
T = table(A,B); writetable(T,...)

5 years ago | 1

| accepted

Answered
How to use "if statement" for different matrix?
The MATLAB approach is to use arrays and indexing, e.g. using one simple cell array: V = {[1,3,5;2,4,7];[1,2,5;2,4,6];[1,4,5;4,...

5 years ago | 0

Answered
Create month array?
D = datetime(2021,1,1):calmonths(1):datetime(2021,12,31) D.Format = 'MMM'

5 years ago | 3

Answered
substract row of an array by a vector
Where A is your array: X = [18,36,54]; A(X,1) = A(X,1) - 2; A(X,2) = A(X,2) + 2;

5 years ago | 1

| accepted

Answered
Best solution to finding repeating characters on a line.
inp = {'asdfsdfsdfsasdfsdfsdfsasdfsdfsdfs';'asseefadfefaaadddaaadddasdfsdf';'asdfsdfsdfsasdfsdfsdfsasdfsdfsdfs';'asseefadfefaaad...

5 years ago | 0

| accepted

Answered
determining spaces between two strings in fprintf function
fprintf('%*s %*s\n',10,' G',5,' G');

5 years ago | 1

| accepted

Answered
How can I iterate obtaining numbers?
You can use dynamic fieldnames: https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html for...

5 years ago | 0

Answered
How to merger multiple .mat files consists of 2D matrix into 3D matrix
Using the files from your comment, and assuming that the filenames all use sufficient leading zeros: D = '.'; % absolute or rel...

5 years ago | 1

Answered
How to store all outputs from this nested for loop
Vs = 0:9; % Variable 1 Vom = 0.1:0.1:1; % Variable 2 Vmu = 0.1:0.1:1; % Variable 3 Ns = numel(Vs); Nom = numel(Vom); Nmu = ...

5 years ago | 0

| accepted

Answered
How to convert "cell array" to "character array"
C = {'A1','B1','C1'} D = vertcat(C{:}) or D = char(C)

5 years ago | 0

Answered
how to extract a field from a nested structure, modify it, and write it back
As this information is missing in your question, I will assume that ALL is a scalar structure. fun = @(n)struct('dur',n, 'typ',...

5 years ago | 0

Answered
Multiply matrix by each element of a vector without a for loop
Let MATLAB do the heavy lifiting for you! Note that RESHAPE operations are computationally cheap as they do not change the array...

5 years ago | 0

Answered
Covert a cell with the same indices into individual matrices
It is not clear to me why you need to split the numeric data into 100 4x4 matrices, just to recombine the numeric data into 16 1...

5 years ago | 1

| accepted

Answered
read mat files with specific and dynamic name format and import data
The best approach is to use the same structure as DIR returns. This has the benefit that the filenames and filedata are automati...

5 years ago | 0

| accepted

Answered
How to subtract number inside cell
A = {[32,28,30,31],[27,29,30]}; B = {[30,64,72,85],[15,33,62]}; C = cellfun(@minus,A,B,'uni',0)

5 years ago | 0

Answered
How to take a number inside cell array
A = {[32,28,30,31],[27,29,30],[32,29,31,27,28]}; B = {[30,64,72,85],[15,33,62],[45,62,77,84,90]}; F = @(a,b)b(max(a)==a); C =...

5 years ago | 0

| accepted

Answered
How to select array elements based on the elements of another array?
idx = ismembertol(eyetimes,spiketimes,0.02, 'DataScale',1); out = eyetimes(idx)

5 years ago | 0

| accepted

Answered
How can I solve an ODE with changing variable over time ?
Replace your Tset function with this: P = 'absolute or relative path to where the mat file is saved'; F = 'name of the mat fil...

5 years ago | 0

| accepted

Answered
save for loop variable in workspace
Given that you are apparently incrementing your own loop counter then presumably you have a WHILE loop. In that case, try this:...

5 years ago | 0

Answered
How can I make a variable span multiple functions for nested structuring?
How to make a variable "cyan" (these are called shared variables) is explained here: https://www.mathworks.com/help/matlab/matl...

5 years ago | 0

| accepted

Answered
Text file generated using MATLAB has invalid characters in it.
Get rid of the SAVE command. It is not completely clear why you added SAVE, but it is writing binary data into the same file th...

5 years ago | 1

| accepted

Answered
Splitting a file into multiple files and need to generate file names from the individual files
whf = fileread('./testsplit.txt'); spl = regexp(whf,'\s+#Z\s+','split'); % more robust than just 'Z' for k = 2:numel(spl) % fi...

5 years ago | 0

| accepted

Answered
How to use effectively use the lazy quantifier for regular expression?
regexp('4223594459854','4.*?4','match')

5 years ago | 0

| accepted

Load more