Answered
How to assign each row of a matrix to a field of a structured array without a loop?
One possible way to avoid for-loop: position = zeros(10,3); pop = table(position,cell(10,1),'VariableNames',{'pos','fit'}); p...

7 years ago | 1

| accepted

Answered
Matrix of Zeroes, Circle of ones in center
One possible straight-forward solution would be like this: [xGrid,yGrid] = meshgrid(1:500,1:500); BW = sqrt((xGrid - 250.5).^2...

7 years ago | 0

Answered
Replace a value if a condition is met
Please try the following: idx = A(:,1) == 3; A(idx,3) = 20;

7 years ago | 0

| accepted

Answered
Plot pdf from histogram - dice
You can set 'Normalization' option of histogram function to 'pdf', like: histogram(SumRoll,Edges,'Normalization','pdf'); If yo...

7 years ago | 2

Answered
Find coordinate position (x1, y1, x2, y2) of multiple rectangle from an binary image
If your rectangle are always horizontal and/or vertical in your images, regionprops function will work, like: % Read the image ...

7 years ago | 1

Answered
Finding peak width at threshold
One simple way to do your task woudl be utilizing pulsewidth function. By setting 'StateLevels' option to [th - delta, th + delt...

7 years ago | 1

Answered
Creating combinations of 3 vectors
One possible solution would be like this: A = [50,20,30; 55,25,35; 60,30,40]; [p1,p2,p3] = ndgrid(1:3); Result = [A(p3(:),1),...

7 years ago | 1

| accepted

Answered
Closing the boundary of an image for segmentation
I think combining boundary and poly2mask functions should be some help for your task. How about the following? % Read the image...

7 years ago | 2

| accepted

Answered
How do I generate a contour map with rand on the axes
In contour function, X and Y should be increasing or decreasing along one dimension. To do so, please sort x and y before meshgr...

7 years ago | 1

| accepted

Answered
How to plot Frequency domain of optical nonlinear Schrodinger equation
Unfortunately, I could not run and check your code. Previously, I have implemented split-step Fourier method (SSFM) to solve ...

7 years ago | 3

| accepted

Answered
How can I remove background around droplet?
How about the following? % Read the image and convert to gray scale I = imread('image0000.jpg'); Igray = rgb2gray(I); ...

7 years ago | 0

Answered
Finding peaks with x and y that are not positive
Comparing your uploaded figure and mat file, you want to find peaks of |-1*a(:,2)| above -75, if my understanding is correct. If...

7 years ago | 0

| accepted

Answered
How can I create a gradient of 255 line plots?
I think the solution would be like this. In this example, like color changes as the y-intercept of the like decrease. % Gra...

7 years ago | 4

Answered
How to keep only solid white dots and eliminate dots that inside them is black in the attached image?
|bwpropfilt| function would be helpful for your task. The following is an example. % Read the image I = imread('Example.jp...

7 years ago | 1

| accepted

Answered
mapping a matrix to array to new matrix (mapping image to tone image )
Like the following ? reshape(B(A(:)+1),size(A))

7 years ago | 0

Answered
Directed matrix to Undirected matrix
How about the following? Y = G + G' > 0;

7 years ago | 1

| accepted

Answered
How to count the number of occurrences of each pair in a cell?
I think one possible way would be like this: c = {[1; 2; 3]; [1; 2; 3; 4]; [1; 2]}; Pair = [repelem((1:4)',4,1),repmat...

7 years ago | 0

| accepted

Answered
Deriving specific rows from a large text files
I would recommend updating your MATLAB to the latest version, since R2015a does not support many useful functions for your task,...

7 years ago | 1

| accepted

Answered
how to convert three dimension daily data into monthly mean?
Let me try it step-by-step: % Load the data load('prec_aphrodite.mat'); % Reshape the data to 730(day)-by-387(site) a...

7 years ago | 1

| accepted

Answered
Remove specific characters from cell array
If string before ':' is always two digit, the following will work. output = regexprep(yourCellArray,'\d{2}:','');

7 years ago | 0

Answered
input alphabet and numbers
How about the following? str = input('Enter with input: ','s'); c = regexp(str,'\d+','match'); output = str2double(c);

7 years ago | 1

| accepted

Answered
Problem with odds and even simulation code
In your code, the variable |n| becomes always 100x1 array. This is the reason why the |ScoreB| always much higher than |ScoreA|....

7 years ago | 1

| accepted

Answered
How to extract all columns of a matrix that have the same 1st colum value as another vector?
I think the solution would be like this: % Example of Master and SiteNo Master = [(1:8000)', 90*rand(8000,2)]; SiteNo = r...

7 years ago | 0

Answered
Specified number of ones in the matrix
If your goal is to obtain the final 4-by-8 matrix, how about the following? A = [zeros(4), eye(4)]; for kk = 1:4 A(kk...

7 years ago | 2

Answered
Find the rows with specific value for each column
Another possible solution. A = randi([1 10],4,10); idx = any(A == 1); % Represents column index in which the value 1 i...

7 years ago | 0

Answered
Convert HH:MM to fractions of a day
I think the solution would be like this. % Sample datetime vector Time = datetime('now') + 3*rand(100,1); Time = sort(Tim...

7 years ago | 0

Answered
How do I rename multiple files located in subfolders within a main folder?
How about the following? D = struct2table(dir('./**/*')); D = D(~D.isdir,:); for kk = 1:height(D) [~,folderName]...

7 years ago | 0

| accepted

Answered
How to use textscan to import time value (hh:mm:ss)
I think it's better to do it step-by-step, like: % Read the file fid = fopen('181018_PL.txt','r'); c = textscan(fid,'%s',...

7 years ago | 1

| accepted

Answered
Create a matrix that contains sine wave
You can avoid for-loop by simply: t = 0:0.001:1; f = 1:5; x = sin(2*pi*f'*t);

7 years ago | 1

Answered
How to crop a certain boundary of an image?
How about the following? Img = imread('irregular-shape-leaf_21197202.jpg'); Igray = rgb2gray(Img); BW = ~imbinarize(Igray...

7 years ago | 1

Load more