## How can I calculate the shortest distance from a point to a line segment?

I wanna write a neat code to compute the shortest distance between a point and any line segments in any directions. I understand that in many cases the shortest distance would be a line perpendicular from the point to the line segment and in some cas

## Fill missing timestamp data lines with NAN - MATLAB

I have one dataset in which some timestamps are missing. I have written code so far as below, x = table2dataset(Testing_data); T1 = x(:,1); C1 =dataset2cell(T1); formatIn = 'yyyy-mm-dd HH:MM:SS'; t1= datenum(C1,formatIn); % Creating 10 minutes of tim

## How to remove a variable from the .mat file in matlab?

I have in my file .mat three matrices, I need to delete one of them. I try clear ('Matrice1'), but it doesn't work.If you absolutely must completely delete the entire variable the most straightforward option is to load the data, remove the variable,

## Matlab range in Python

I must translate some Matlab code into Python 3 and I often come across ranges of the form start:step:stop. When these arguments are all integers, I easily translate this command with np.arange(), but when some of the arguments are floats, especially

## Convert meshgrid to vector for a 2-valued function

I have a function like f = @(x) x(1).^2 + x(2); I want to draw its plot via surf, so I used meshgrid to generate input data: [x, y] = meshgrid(-2:.2:2); But if I try to pass it to the function like this z = f([x; y]) I get just a single value in resu

## Read the char table line in matlab

What I have I've a char array, defined by doing an strcat between two char arrays like this: coeficientes = strcat(coef_bin, coef_bin_comp) Then, I want to read each row and convert them to hex. I'm doing it like: for k=1:11 coef_binario = coeficient

## Get a list of all subdirectories of Matlab

I'm trying get an absolute path of all subfolders in project_dirs. project_dirs='D:\MPhil\Model_Building\Models\TGFB\Vilar2006\SBML_sh_ver\vilar2006_SBSH_test7\Python_project3_IQM_project'; all_project_dirs=dir(project_dirs) for i=all_project_dirs, f

## how to refresh a Matlab window and leave it where it was in Z order

My script on Windows 7 has multiple matlab figures (windows). When I periodically re-display the disparity figure, it always brings it to the front of the other windows. I want to leave it where it was, in the Z order. if isempty( disparity_map_figur

## Matlab: passing large tables or loading from a .mat file

I want to use large arrays with 1.0e6 elements in other Matlab functions. Currently I am using small sized arrays and passing them as function input. I do not how much this passing of arrays going to affect the speed of my program when I use large ar

## Create a Function Input Matrix Array in Matlab

I would like to create several matrices to represent Hilbert matrices of different orders. The matrix will then be called by a function. However, error messages appeared saying that the function(GE) is not defined. But if I put the function on top of

## Definition of a generic function for the iterated function composition

Let us define any function handle foo: foo = @(x) x*2 I am trying to write a general function defFun that generates the n-th functional power of the function foo, i.e. n iterative calls of foo, in a way it can be stored in another handle function boo

## Why does Matlab's contourf function not use the highest value of the plotted data?

does anybody know why the function countourf doesn't use the color corresponding to the maximum value anywhere in the plot area? if you try the code below, and then the command get(h_colorbar,'YLim') Matlab returns an upper limit which is not the hig

## Matlab: Finds nearby instances of NaN without loops

Essentially, I have a matrix of data with many "holes" represented by NaN, and I want to retrieve the indices of all NaN's that are clustered fewer than 4 times in a single column. e.g. with the matrix: A = 23 12 NaN 56 60 21 NaN 60 56 94 22 45

## Do Variables Contain Additional Hidden Metadata - aka When is zero not zero (but still is)

I hate having to ask this because I assume the answer must be simple, but I cannot for the life of me seem to track down the source. While trying to rewrite a function I ran across this problem: a = -j x = real(a) y = imag(a) y/x Which spits out Inf,

## Compare a string to all elements of a table

How do I get the result when '@' exist in the string will return 1 else 0. Now, I get the results of 0 0, although second string contain the character of '@'. A = {'@'}; B = {'http://www.mathworks.com/help/matlab/ref/strcmpi.html', 'http://www.mathwo

## NaN values ​​of the Matlab comparison tool

I am trying to compare two .mat files using the Matlab Comparison Tool. In the comparison result the NaN values are highlighted meaning they are different (even though they are not). How can one handle the NaN values when using the Matlab Comparison

## I want to extract the number of special characters and the number of vowels in each sentence using a matlab command

I have a cell in Matlab with 5 strings in it, each string being a sentence and I want to pull out the number of special characters and the number of vowels in each sentence using a Matlab command. How would I do this? Here is my code: sentences={['Do

## Extracting variables when reading in data files

I am quite new to data analysis, so if this is a rookie question, I'm sorry, I am learning as I go. I have just started doing some work in variable star astronomy. I have about 100 files for every night of observation that all contain the same basic

## Matlab: Finding a y-values ​​root given by a differential equation

I've solved an initial value differential equation and plotted the Y values given by ODE45. From the plot I can vaguely tell where the root should be, but in the given task I need to find it with great accuracy. My first guess was to adjust a polynom

## Subplots of Matlab pressed

I try producing a 14 x 5 subplot in Matlab, however the subplots have square axes so when displayed the subplots are not legible. Similarly, when I plot the results to pdf, the subplots are too small to read. How can I prevent this problem?If you don

## make the axes invisible or completely remove the path

I have a matlab gui that shall contain 4 plots. The first plot shall be updated if a different file is selected in a list. the other 3 shall only be visible (and be calculated) on request. However I fail to make plots 2-4 invisible after they have be

## Change the time vector

I have a vector of time (format h,min,sec,msec). TIME_= [120844.950000000 120853.870000000 120854.120000000 120854.370000000 120854.620000000 120854.860000000 120855.100000000 120859.980000000 120900.220000000 120900.490000000 . . . 121024.420000000

## Drawing mask above the MATLAB grayscale image

I'm running an algorithm to segment part of an image using morphological operations. I end up with a 2D binary image that represents the segmentation results. Namely, the mask. My question is how to plot the original image and the mask overlay in col

## Selecting elements from a matrix in matlab

I have a matrix which is 36 x 2, but I want to seperate the elements to give me 18, 2 x 2 matrices from top to bottom. E.g. if I have a matrix: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... ... I want to split it into seperate matrices: M1 = 1 2 3 4 M2 = 5 6

## matlab and c ++ precision

Hi I'm rewriting a script from MATLAB to C++ using armadillo library for linear algebra and matrix. for getting more or less the same output i called cout method: cout.precision(4); cout.setf(ios::fixed); but i'm getting different result: Matlab resu

## Representing three variables in a three-dimensional plot

I have a problem dealing with 3rd dimension plot for three variables. I have three matrices: Temperature, Humidity and Power. During one year, at every hour, each one of the above were measured. So, we have for each matrix 365*24 = 8760 points. Then,

## How to extract part of the image within the limit specified in MATLAB

I am new to MATLAB, i wanted to know that can i extract a part of image from inside of a specified boundary,based on distinguishing color(red boundary in my case),The function,first traces the boundary of the image,then it extracts that part of image

## How to normalize the data around the average of the column in MATLAB?

I am trying to take a matrix and normalize the values in each cell around the average for that column. By normalize I mean subtract the value in each cell from the mean value in that column i.e. subtract the mean for Column1 from the values in Column

## Vector of the sum of different diagonals in a matrix

I want to vectorize the following MATLAB code. I think it must be simple but I'm finding it confusing nevertheless. r = some constant less than m or n [m,n] = size(C); S = zeros(m-r,n-r); for i=1:m-r+1 for j=1:n-r+1 S(i,j) = sum(diag(C(i:i+r-1,j:j+r-

## How to get full division quotient in matlab?

I wonder how to get quotient in integer division in MATLAB? Thanks and regards!Use idivide: C = idivide(A, B) is the same as A./B except that fractional quotients are rounded toward zero to the nearest integers. There's a third optional parameter for