Answered
Unexpected for loop behaviour
"Unexpected for loop behaviour" The value -0.1 cannot be represented exactly using floating point numbers, and you could quite ...

7 years ago | 1

| accepted

Answered
random numbers without repetition of two consecutive numbers
Adapting John D'Errico's answer to an earlier question: >> n = 5; >> k = 4; >> t = 100; >> 1+mod(cumsum([randi(k,t,1),randi(...

7 years ago | 5

Answered
Finding length of a struct, excluding NaN values
You can do this very easily with the accepted answer to your very similar question from two months ago: https://www.mathworks.c...

7 years ago | 2

| accepted

Answered
How to Overwrite Data
One simple MATLAB way: C = max(A,B).*(B~=0) Or for MATLAB versions prior to R2016b: C = bsxfun(@max,A,B).*(B~=0)

7 years ago | 0

| accepted

Answered
Does findpeaks work with mat files?
Most likely you need to actually refer to the structure that you imported the file data into: S = load('mytrace2131soma&syns.ma...

7 years ago | 0

Answered
Read only numbers from string
"Given a string, how to read only the numbers?" That really depends on what you define as being a "numberˇ: which of these are ...

7 years ago | 0

| accepted

Answered
help to use for loop in four layer
Without loops: >> [X,Y,Z] = ndgrid(1:3); >> A = permute(cat(3,p(:,Z),ommega(:,Y),v(:,X)),[1,3,2]); And checking with some exa...

7 years ago | 1

| accepted

Answered
Putting Consecutive numbers into variables
>> A = [1;2;3;7;0;6;7;8;9;2;4;3;14;15;16;17;0;9;2]; >> D = diff([false;diff(A(:))==1;false]); >> F = @(b,e)A(b:e); >> C = arr...

7 years ago | 0

| accepted

Answered
Meet multiple conditions (or)
Use ismember: ismember(peroxi_3d_lab,your_conditions_array) Tip: with MATLAB it is always important to think in terms of opera...

7 years ago | 0

| accepted

Answered
Use one matrix to change values of another
Method one: indexing: >> X = ismember(B,A) >> B(~X) = 0 B = 1 2 3 4 0 0 0 0 1 2 ...

7 years ago | 1

| accepted

Answered
regex: Extract then delete
"Is there a regex function that can extract matched strings and delete them after?" Not really. You could do something like th...

7 years ago | 0

| accepted

Answered
Using a matrix as pairs of indexes of another matrix
"How can this be done without a loop?" Using sub2ind, which converts to linear indices: >> ind = sub2ind(size(x),idx(:,1),idx(...

7 years ago | 0

| accepted

Answered
Counting the Same Occurance of a row string
>> P = {'ADS','µSOIC8';'AVX','0603';'AVX','0603';'AVX','0603';'ELN','';'EPC','0603';'EPC','0603';'EPC','0603';'FAG','DO214AA';'F...

7 years ago | 1

| accepted

Answered
How to removing data of structure field?
>> st = struct('piece',{1,1,3,4},'food',{'cheerio','marshmallow','pizza','cereal'},'yes',{0,'food','no',0},'maybe',{'cereal',3,'...

7 years ago | 1

| accepted

Answered
Cropping image with actual pixel size
Do NOT use saveas. saveas is basically like taking a screenshot of a figure. Not very useful for your case. You need to use im...

7 years ago | 0

Answered
Iterating through an array without using a for loop
theta = 0:0.1:2*pi/5 theta(:) = rand(1,numel(theta))

7 years ago | 0

Answered
how to compare each elemnets in two cell with error tolerance?
>> A = {[1,2,3],[1.2,5,2.4]}; >> M = bsxfun(@rdivide,A{2},A{1}.'); >> [A1,A2] = find(abs(M-1)<=0.2) % 20% A1 = 1 ...

7 years ago | 0

| accepted

Answered
Extracting multiple sets of scientific notation data
Try this sscanf format string: '%d%f' However your file-importing code is rather complex. Here is a simpler method using texts...

7 years ago | 0

| accepted

Answered
split columns and save seperate .mat files
Simpler, much more robust, much more versatile code (without bad code practices such as dynamically accessed variable names, loa...

7 years ago | 0

| accepted

Answered
How to code below mathematical formula?
The simple MATLAB solution: >> x = 1:30; >> t = 23; % threshold >> MYOP = sum(x>=t)/numel(x) MYOP = 0.26667

7 years ago | 1

| accepted

Answered
Preallocate memory for the rows of each field inside a structure
This should get you started: >> S = struct('F',{[],[],[]}); >> S.F ans = [] ans = [] ans = [] >> [S.F] =...

7 years ago | 0

Answered
How can I save Python dictionaries in Matlab?
A simple approach: within MATLAB save the data in a .mat file. within Python load the data using numpy.io. rearrange the data...

7 years ago | 0

Answered
How to turn a column of seconds into the datetime-type?
The simple MATLAB solution using datetime and duration classes (no outdated datevec): T.TIME_S = zinterval + seconds(T.TIME_s) ...

7 years ago | 1

| accepted

Answered
Nested loop problem with the second index
The simple MATLAB way: >> cpx = [1,3,5,7]; >> cpy = [22,44,66]; >> [X,Y] = ndgrid(cpx,cpy); >> M = [X(:),Y(:)] M = 1 ...

7 years ago | 0

Answered
saving a variable from GUI
You forgot to actually pass those variables back to the main workspace: https://www.mathworks.com/help/matlab/creating_guis/sha...

7 years ago | 0

Answered
Diff matrix in cell array
Given one cell array A, this seems to matche your example: F = @(m)-diff(m,1,2); Y = cellfun(F,A,'uni',0)

7 years ago | 0

| accepted

Answered
Changing portions of variable names
Use this as the new filename: strrep(rawdata,'.csv','.dat') Or more robustly: [~,fnm] = fileparts(rawdata); sprintf('%s.dat'...

7 years ago | 0

| accepted

Answered
For loop pass in unique rows to function
M = [1,2.5,3,5;1,3,4,5;1,5,7,5;2,4,5,6;2,6,8,9]; U = unique(M(:,1)); for k = 1:numel(U) X = U(k)==M(:,1); yourFuncti...

7 years ago | 1

| accepted

Answered
cant find the mistake here
Well you made a good starting attempt, the main bug with your code are these ranges: for i = 1:a for j = 1:b Using those ...

7 years ago | 0

Answered
Append a char vector to a subset of cells (whose indices are known) in cell array of character vectors
Your basic concept is correct, you just need to use indexing on the LHS as well as the RHS: mycell(calidx_rng) = strcat('cal_',...

7 years ago | 1

| accepted

Load more