https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-04-10T18:30:34Ztag:it.mathworks.com,2005:Question/7981522021-04-10T13:17:51Z2021-04-10T18:30:34ZFind offset between two datasets based on timestamps | closest distanceHello,
I have two sets of data, each with a timestamp. Unfortunately the offset is unknown. In the first dataset (No 1) events are individually registered. In the second dataset (No 2) the events happen continously.
While the individual measurements of sensor 1 are registered, the noise of the sensor 2 is very low. Due to this, it can be assumed that at the end of a low-noise period an individual measurement happened. These timestamps can easily be filtered. Unfortunately not at every low-noise period from sensor 2, a measurement of sensor 1 is done. Hence there are more (filtered) timestamps from the second sensor than from the first one.
Now, my idea is to find the offset between the two datasets by aligning the registered timestamps of both sensors. The question is, how can this be done? E.g. closest distance of two datasets? pdist2 seems not to be applicable since it expects 2d vectors. Here I have two 1d vectors.
close all; clear all; clc
%% import
load('estOff');
%% temporary offset to bring timestamps closer together
offset = sensor1(1,1) - sensor2(1,1);
sensor2(:,1) = sensor2(:,1) + offset;
%% plot
figure
hold on
% plot sensor 2
plot(datetime(sensor2(:,1),'ConvertFrom','epochtime','TicksPerSecond',1e3,'Format','dd-MMM-yyyy HH:mm:ss.SSS'),sensor2(:,2),'.')
% plot possible measurements at the same time as sensor 2
plot(datetime(sensor2(increase,1),'ConvertFrom','epochtime','TicksPerSecond',1e3,'Format','dd-MMM-yyyy HH:mm:ss.SSS'),sensor2(increase,2),'*')
% plot sensor 1
plot(datetime(sensor1(:,1),'ConvertFrom','epochtime','TicksPerSecond',1e3,'Format','dd-MMM-yyyy HH:mm:ss.SSS'),-1,'g*')
hold off
Cheers!
010101https://it.mathworks.com/matlabcentral/profile/authors/8496181tag:it.mathworks.com,2005:Question/7967522021-04-08T19:48:50Z2021-04-10T18:28:23ZLinear approximation of data set's points.i have a data set (x,y) that i have to approximate with a piecewise linear function, such that lower and upper bounds are satisfied. the image show what's the result I would like to achieve (in red the data set's points; in grey, the linear continuous approximation i would like to describe)image of result to achieve.
Using Matlab, i've divided all points in groups (one for every linear segment) and approximated every linear segment, with needed constraints, in the sense of least squares. But i need to have a continuous function and I am stuck in solving the problem. There's someone that have an idea of what i can do to solve the problem?
thanks in advance to everyonealessio morabitohttps://it.mathworks.com/matlabcentral/profile/authors/8178855tag:it.mathworks.com,2005:Question/7983222021-04-10T17:27:22Z2021-04-10T18:24:36ZIssue with solving an equationHi,
I am new to MATLAB and I needed to solve the equation below for different values. However, y function should give me multiple values while it is only giving me a single value (106.2).
Can someone please tell me what the problem with the code is.
clc
x = [100:100:6000];
y = (3500*sqrt(x/30))/(1.4*sqrt(x/30)+0.115*x-276);Abdulrahman Alshalawihttps://it.mathworks.com/matlabcentral/profile/authors/17470701tag:it.mathworks.com,2005:Question/7983472021-04-10T18:21:07Z2021-04-10T18:22:07ZWait for user input to select region of data from plot and save it to a variableI have a list of files named sequentially (E.g. "Run1.csv", "Run2.csv", ..... ) that I am reading using "readtable" and plotting the contents using a for loop. I am generating a figure for each file in the for loop.
%% Tidy up workspace
clc; clear; close all;
%% Load raw data
ir_dir = "Path to directory 1\";
ptv_dir = "Path to directory 2\";
% Constants
num_runs = 28; % Number of files
for i=1:num_runs
% create dynamic file path
ir_fname = "Run" + num2str(i) +".dat";
ptv_fname = "Run" + num2str(i) +".csv";
ir_fullpath = ir_dir + ir_fname;
ptv_fullpath = ptv_dir + ptv_fname;
% Read data
tblIR = readtable(ir_fullpath);
tblPTV = readtable(ptv_fullpath);
% plot data
figure(i);
plot(tblIR.Time,tblIR.Data1,'--r','LineWidth',2);
hold on;
plot(tblIR.Time,tblIR.Data2,'-c','LineWidth',1.5);
plot(tblIR.Time,tblIR.Data3,'-m','LineWidth',1.5);
plot(tblPTV.Time,tblPTV.Data4,'-k','LineWidth',2);
plot(tblPTV.Time,tblPTV.Data5,'-b','LineWidth',2);
plot(tblPTV.Time,tblPTV.Data6,'-g','LineWidth',2);
hold off;
grid on;
xlabel('Time (hh:mm:ss.sss)');
ylabel('Temperature (C)');
legend('Data1','Data2','Data3','Data4','Data5','Data6','Location','southeast');
title("Run #" + num2str(i));
% Wait for user input to select data and save it to a variable (data
% brushing?? -- How to automate this?)
% After user has selected data using data brushing and data is saved,
% continue with for loop execution
clear tblIR;
clear tblPTV;
end
Here is an example of output plot that I get after each iteration of for loop:
After the plot is generated, I want the for loop to pause for user to select a region of data in the plot. Something like this:
Upon selection of the data using data brush, I want to data to be saved into a variable in the workspace and continue on with next iteration of for loop.
Is it possible to automate this data brushing for each iteration of for loop? Is there a way to invoke data brushing automatically when a figure is generated? and to automatically save the results of data brushing to a variable? Rakshith Badarinathhttps://it.mathworks.com/matlabcentral/profile/authors/10908925tag:it.mathworks.com,2005:Question/7981472021-04-10T13:11:54Z2021-04-10T18:21:30ZSearch for minimal value in column of table when value in other columns are the sameHi,
I am trying to use Matlab to find the fastest route to travel from an origin to a destination. In the attached image I am showing a few rows of the table that originally contains 70000 rows. So what I need is to get a '1' in column '7. fastest_route' when the value in column '5. route_with_delay' is the smallest value of all values in column 5 with the same origin (column 2) and destination (column 3).
Maybe good to mention is that it is not always the case that each origin and destination have two different routes, but that could also be 1 or 10 or something.
It would be great if someone could help me out!
Best regards,
Aron
Aron Vossebeldhttps://it.mathworks.com/matlabcentral/profile/authors/6873773tag:it.mathworks.com,2005:Question/7982872021-04-10T16:37:45Z2021-04-10T18:15:28ZHow can I store the result after each iteration in a row vector?Below is the sum equation which is of similar form that I need to write in my Objective Function.
I have written the following code using two 'for' loops, it's working fine but the final answer Asum(As) it is storing is only of the last iteration.
Ad = [1 2];
Ac = [1 2 3 4];
for i=1:lenght(Ac)
for j=1:length(Ad)
As=Ad(j)+Ac(i)
end
end
whereas I need the result in the form of a row vector as shown below:
As = [2 3 3 4 4 5 5 6]
Kindly help, thanksSakshi Koundalhttps://it.mathworks.com/matlabcentral/profile/authors/19141002tag:it.mathworks.com,2005:Question/4755752019-08-09T14:53:51Z2021-04-10T18:12:54ZHow can I select 2 columns from each option of a pop menu when I press the load button from a .csv fileSolvedGemma Malagónhttps://it.mathworks.com/matlabcentral/profile/authors/11981222tag:it.mathworks.com,2005:Question/4779722019-08-28T19:18:58Z2021-04-10T18:11:32ZHow can I correct the baseline shift of the signalI'm processing EMG signals an there seems to be a shift of the signal on the raw and filtered signals. I'm using a bandpass filter, and the correct cutt off frequencys. Any clue how can I fix it?
Gemma Malagónhttps://it.mathworks.com/matlabcentral/profile/authors/11981222tag:it.mathworks.com,2005:Question/7983422021-04-10T18:08:47Z2021-04-10T18:08:47Zhow to understand .sc .mat in matlabHello,i cant see the logic of these two lines taken from the full code shown bellow.
i know that its some how plotting an area but .mat .sc are resembling . command from c# of object oriented.
How to understand the meaning of the two lines shown bellow?
Is there any material i could use explaining examples for this structs?
Thanks
func_in.mat=NmidCirc;
func_in.sc=scale;
full code:
lambda=633e-9;% wave length in [m]
L=0.01;% meter factor, it is defined that 1cm=1024 pixels-> the first scale will be over 1cm
scale=linspace(-L/2,L/2,n);% basic scaling vector in length of 1024.
%% Q2 creating matrix
[X, Y]= meshgrid(scale,scale);% creating the basic function. on the function we will create the images that will operated
midCirc= X.^2+Y.^2<(1/n)^2;%because we work in meter units, the 100/1024[cm] transforms into 1/1024[m]
NmidCirc=not(midCirc);
Ring= ((X-0.8/n).^2+(Y-0.8/n).^2<(1/n)^2)&((X-0.8/n).^2+(Y-0.8/n).^2>(0.6/n)^2);
NRing=not(Ring);
Tshape= (abs(Y)<0.2/n)&(abs(X)<0.6/n) | ((Y<1.4/n)&(Y>0.2/n)&(abs(X)<0.2/n))
%%%% Negative cirle part
func_in.mat=NmidCirc;
func_in.sc=scale;
figure(2)
colormap gray
for j=1:6
func_out=Rdiv(func_in,lambda,Z(j),n);
subplot(2,3,j);
image(func_out.sc, func_out.sc, abs(func_out.mat), 'CDataMapping','scaled');
xlabel('[m]');
ylabel('[m]');
title(['Z=',num2str(Z(j))]);
endfima vhttps://it.mathworks.com/matlabcentral/profile/authors/8659326tag:it.mathworks.com,2005:Question/7982922021-04-10T16:49:01Z2021-04-10T18:05:19ZDealing with very small or very large numbersI have a physical problem with length scales on the order of nanometers. After some calculations, I have to calculate things like exp(-1e15) which is 0 according to MATLAB, but in reality it is nonzero. For context exp(-700) is already 9.8e-305 which is close to the smallest number in MATLAB 2.2251e-308. Is there a known workaround for things like his? Anthony Gurunianhttps://it.mathworks.com/matlabcentral/profile/authors/13423715tag:it.mathworks.com,2005:Question/7969772021-04-09T03:44:07Z2021-04-10T18:03:48ZHow to iterate an equation?Hi I got a problem with iterating an equation and I have to estimate a value from it. Anyone has an idea?
Thanks!Ka Wai Yiphttps://it.mathworks.com/matlabcentral/profile/authors/14886087tag:it.mathworks.com,2005:Question/7983372021-04-10T17:57:10Z2021-04-10T17:57:31Zhow to load images in orderhi i have 520 images in total
20 images in 26 files
each images is names 1 to 20 and files 1 to 26
i want to load them 1 by 1 and put them in a matrix or process them
im looking for something like this :
for ii=1:26
for jj=1:20
a=load('C:\Users\Nik\Desktop\NNDL-Pr1\English Alphabet\ii\jj.png');
*process codes*
end
end
thank youKamyar Mazareihttps://it.mathworks.com/matlabcentral/profile/authors/21972982tag:it.mathworks.com,2005:Question/7982372021-04-10T15:17:30Z2021-04-10T17:56:04ZSeparating Objects in Binary ImageHey there,
I'd like to separate the objects from the surrounding circle. I would choose operations like imopen, but the area of all objects within the circle should remain the same. I do not need the circle.
Thanks for your help!Lukas Schmitthttps://it.mathworks.com/matlabcentral/profile/authors/22158371tag:it.mathworks.com,2005:Question/7983322021-04-10T17:54:01Z2021-04-10T17:54:01Znormalization when calling fitnetDoes MATLAB normalizes the input by default when calling 'fitnet' or 'train' ??? if so how can I check it ? and how does it do it?Abdulaziz Almershedhttps://it.mathworks.com/matlabcentral/profile/authors/18103763tag:it.mathworks.com,2005:Question/324832012-03-16T15:10:24Z2021-04-10T17:48:06Zplease tell me the coding of how to embed a image into another image by using LSB....i need ithow to insert an image over another image using LSB and watermarking..Manishahttps://it.mathworks.com/matlabcentral/profile/authors/3190554tag:it.mathworks.com,2005:Question/7982622021-04-10T15:59:38Z2021-04-10T17:47:18Zunderstanding "<" operator lineHello,I cant understand a line of the line bellow taken from the code bellow.
I think i generates a circle but i cant see how .
When i tried to use "<" operator it ony gave me true or false
Could you please give me simple example of using this principle of the line bellow?
midCirc= X.^2+Y.^2<(1/n)^2;
Thanks.
n=1024;% matix dimmensions
lambda=633e-9;% wave length in [m]
L=0.01;% meter factor, it is defined that 1cm=1024 pixels-> the first scale will be over 1cm
scale=linspace(-L/2,L/2,n);% basic scaling vector in length of 1024.
%% Q2 creating matrix
[X, Y]= meshgrid(scale,scale);% creating the basic function. on the function we will create the images that will operated
midCirc= X.^2+Y.^2<(1/n)^2;%because we work in meter units, the 100/1024[cm] transforms into 1/1024[m]
NmidCirc=not(midCirc);
Ring= ((X-0.8/n).^2+(Y-0.8/n).^2<(1/n)^2)&((X-0.8/n).^2+(Y-0.8/n).^2>(0.6/n)^2);
NRing=not(Ring);
Tshape= (abs(Y)<0.2/n)&(abs(X)<0.6/n) | ((Y<1.4/n)&(Y>0.2/n)&(abs(X)<0.2/n));
NTshape=not(Tshape);
figure(100)
colormap gray;fima vhttps://it.mathworks.com/matlabcentral/profile/authors/8659326tag:it.mathworks.com,2005:Question/7934272021-04-05T20:55:41Z2021-04-10T17:37:22ZHow to solve inverse kinematic problem in real-time?I want to make a real-time end-effector position control simulation of a 6 DOF robotic arm in simscape multi-body. In the simulation I want to make a matlab GUI like sliders to change the posiotion and the robotic arm starts to move in real-time. To do so, I should solve the inverse kinematic problem and the best way is to use matlab robotic toolbox. The problem is even with using this toolbox, robot cannot move in real-time and it should be done offline. Can anyone help me with that or suggest me a solution?
As I know, industrial robots like KUKA or ABB can solve the inverse kinematic problem in real-time or may be they use lookup table for moving in their workspace.Ehsan Amirpourhttps://it.mathworks.com/matlabcentral/profile/authors/22103545tag:it.mathworks.com,2005:Question/7983172021-04-10T17:23:16Z2021-04-10T17:32:07ZSearch and split 3d peaks from a 3d plot Dear All
I am working on a script for searching and retrieve the relative volume integrals of several peaks posed in a 3d spectra. The data are composed by two axis X (1024 points), Y(512 point) and a matrix d (1024x512 points).
Right now I am quite able to search the peaks with some alrerady exsisting functions (e.g: imragionalmax() in 3d or findpeaks() in 2d/1d ) even introduncing a treshold in the function output.
My questions come now, after the identification of the peaks I should get the total itegral of the peaks, How can I do that task ? Do you have any suggestion on which exsiting functions I can use ?
I think that maybe with the brush function, I could manually do the task. But the main problem would be to automate this procedure for all of the peaks.
In other hands the flow path that I have in mind is :
single 3d plot (multiple peaks) -------> multiple 3d plot containing the single Peaks --------> Integrals of the Peaks
Any suggestions are welcomed
Thanks
Enjoy
Ffrancesco_123https://it.mathworks.com/matlabcentral/profile/authors/18091246tag:it.mathworks.com,2005:Question/3087532016-10-23T20:58:56Z2021-04-10T17:18:16Zwhat is matlab code for MSE and PSNR of 2 images?Image ProcessingAniruddha Rakshithttps://it.mathworks.com/matlabcentral/profile/authors/9014579tag:it.mathworks.com,2005:Question/7796722021-03-22T07:02:57Z2021-04-10T17:16:56Zhow to write algorithm for code?node = 3;
Link = (node-1)*node/2
NN = toeplitz(Link+1:-1:2);
mask = logical(fliplr(diag(ones(1,Link-1),-1)));
NN(mask) = 1;
for c = 0:2^Link-1
out = bitget(c, NN)
end
format long g
lamda = 0.7;
bits = dec2bin(0:2^node-1)-'0';
nl = sum(bits,2);
nu = node-nl;
P = lamda.^nl .* (1-lamda).^nu;
P(1:8)
[minP, minidx] = min(P)
bits(minidx,:)
[maxP, maxidx] = max(P)
bits(maxidx,:)
please help me to write algorithmSrinivas Srinivashttps://it.mathworks.com/matlabcentral/profile/authors/18769641tag:it.mathworks.com,2005:Question/7983122021-04-10T17:13:50Z2021-04-10T17:13:50Zxlswrite substitute that writes to specific columns I would like to write a matrix to specific columns and rows of excel. xlswrite has this option but for compatibility issues I would want to find a substitue for it. Writetable or writematrix does not have this option (xlswrite(filename,A,xlRange)).
Any idea?Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884tag:it.mathworks.com,2005:Question/4885372019-10-31T13:06:15Z2021-04-10T17:13:16Z'Plots' and 'training-progress' as a name-value pair argument in trainingOptions. I am using R2019a MATLAB version.
I want to plot the training progress of my training data in convolutional neural network , but I get 'Plot error.Training continues unaffected' on Training Progress window when I use 'plots' and 'training-progress' as a name-value pair argument in trainingOptions.
How can I solve this problem?Tao Yanghttps://it.mathworks.com/matlabcentral/profile/authors/15325585tag:it.mathworks.com,2005:Question/7935372021-04-06T00:43:55Z2021-04-10T17:11:37ZWhich version of MATLAB will provide functional (i.e. working) GUI interactions?Thsi is a very straightforward question, and hopefully there will not be roundabout / indirect answers. Surely, everyone that has used this software is aware that its GUI is severely broken. That is, completely dysfunctional in some very critical ways. We are coming from an open-source pipeline that is well streamlined but mostly headless. We wanted to use the MATLAB GUI as a testing ground for basic functionality. Unfortunately, it would appear the GUI doesn't work in either Linux or Windows (we have tested multiple computers and architectures), and the issues don't stop at a lack of GUI functionality but, apparently, in engine agility / performance as well.
Case in point -- the toolbox of interest -- Lidar Camera Calibration -- allows the specification of image and point cloud folders, but processing just a single pair takes roughly 5 minutes on a 32-core CPU with 8Gb RTX 2070 GPU. We use this same workstation to run very elaborate machine learning algorithms with big data analysis. All of the GPU intensive workflows that manipulate multi-million point clouds, ICP matching, etc. are able to process hundreds of clouds in minutes --- meanwhile, MATLAB is laboring over single pairs for up to 1 hour (for 50 pairs). Even just 4 pairs will consume over 10 minutes. This kind of performance is absolutely unacceptable.
But that is not what I am opening this query about. Even once the pairs have been analyzed, MATLAB apparently isn't sophisticated enough to automatically identify a checkerboard plane, for example, in the point cloud that corresponds to a 2D image --- something that PCL, for example, can do with absolutely no issue using RANSAC. Moreoever, in the graphical interface, it is not possible to edit the ROI. There is an "Edit ROI" button, but the software is so unconscionably slow that just changing from rotation to panning or zoom will invoke a 30-60 second delay, and there is absolutely no possibility for doing anything whatsoever with the bounding box around the points. Moreover, (and perhaps more surprising than anything else) there is no detailed documentation for this interface.
I understand many of the "veterans" here are using the command-line interface exclusively, but I see no need to take on a new language when the platform itself grossly underperforms literally every other GPU-based open-source project out there. I wanted to give MATLAB a chance to show its capability for computer vision, but this first impression, unfortunately, will be quite difficult to reverse. I originally thought the lack of performance and efficiency in the engine and GUI were Linux based, so we moved off the machine learning laptops and onto the more robust desktops. The same behavior is seen regardless of system or OS -- so it's clearly a design flaw.
We were interested in purcashing 100+ licenses for our research branch, but it's clear, both from reading the complaints here in the forums, and observing the overall benchmarks conveyed in other threads -- that it would have been a costly mistake. I wanted to leave this post here, just on the odd chance that someone -- somewhere -- has run into these issues and is aware of of a workaround.
I doubt many people are using the Computer Vision functionalty of this suite, or else these problems would likely be more visible and addressed in a timely fashion. Perhaps it is a limitation of 2021a. I cannot say, because this is our first (and last) excursion with MATLAB. Hopefully, the developers monitor these threads and will take some honest and well-intentioned criticism for the product, in general.
My suggestion would be to open-source this software, given that it has not yet achieved commercial-level stability. It's very far from being a product worthy of even a meager price-tag, with these obvious and unacceptable flaws, and I can't imagine Mathwork's profit margin can be even remotely robust -- unless there are more people out there than I would care to imagine that are OK waiting hours for their algorithms to run rather than seconds with open-source. That leads to another unrelated question, "why pay for this when you can do better for free", but this is clearly not the right place to post such a question. I am open to the possibility that there may be ways to optimize the engine (but doubtful, since such optimizations would be expected to be automatically engaged as part of the base installation).Anatoliy Jandahttps://it.mathworks.com/matlabcentral/profile/authors/22016768tag:it.mathworks.com,2005:Question/7953172021-04-07T14:56:11Z2021-04-10T17:08:40ZSearching for a matched string within nested cell and delivering the indexI have a nested cell array which is called values.
In this example, there are 5 sub cells. Usually this number is variable from 1 to 30.
Each cell has two subsub cells:
the first one, or values{5,1}{1,1}, has always only one char value (in this example, TOTAL or MGS)
the second one, or values{5,1}{2,1}, has matrix consisting from tow columns: on the left - tempearature values, on the right - physical properties.
My goal is twofold:
to find the sub cell containing the char value 'TOTAL' (values{5,1}) and somehow to get the index of the matrix (the output would be values{5,1}{2,1}).
to get from the matrix the physical property at 298,15. If the value for room temperature is missing, take the closest value to the RT (the output would be 7 or 6 (if the value at room temperature is missing))
To adress the 1st problem, I have written my handmade solution. This code works if there is in the char TOTAL in a{5,1}{1,1}. However, this string could be elsewhere. In this case, I have a problem.
To find a solution for the 2nd question, I created following script, which from my point of view could be simplier to read.
for m = 1:numel(values)
for n = 1:numel(values(m))
a = values(m);
if string(a{5,1}{1,1}) == 'TOTAL'
k = a{5,1}{2,1}(:,1); %column with temp numbers
n = 298.15; %RT
[~,~,idx] = unique(round(abs(k-n)));
minVal = k(idx==1);
valueAtRT = sprintf('%f', a{1,1}{5,1}(length(a{1,1}{5,1})+idx));
break;
end
end
end
How can I do this?
Thanks for any help.
Nazar Adamchukhttps://it.mathworks.com/matlabcentral/profile/authors/19527025tag:it.mathworks.com,2005:Question/7979822021-04-10T06:06:36Z2021-04-10T17:02:38Zcombine cell values in excelI have an input excel sheet
n that excel l have few datas as shown below
if there is string 'o1' (o comes before 1) i need to take the cell value before o1 (eg: shown in yellow color), i need to combine those 2 cell value and store the new value (a1 and g1) to a single cell as shown in the second excel (in yellow color)
if the string is '1o' (o comes after 1), i need to take the cell value after the value 1o (eg: shown in green color), i need to combine those two cell values and store the new value (1d and 1e) to a single cell as shown in the second excel (in green color)
if the string is '1o' , i need to check one more condition - i need to check if the cell value after the alphabet is o1 - if it is o1 (eg: shown in pink color), i need to combine the three cell values and store the new value (1i1 and 1k1) to a single cell as shown in the second excel (in pink color)
Cant this be done in Matlab?Elysi Cochinhttps://it.mathworks.com/matlabcentral/profile/authors/3625227tag:it.mathworks.com,2005:Question/7983072021-04-10T17:01:12Z2021-04-10T17:01:12ZGenerating a heat map of adjacency matrixI am trying to generate a heat map of an adjacency matrix from a particular graph with only two colours (a 100 x 100 array of squares).
I have the following code so far, with G1 being my function:
B=adjacency(G1);
adj=full(B);
heatmap(B)
Any help would be appreciated
Joseph Turnerhttps://it.mathworks.com/matlabcentral/profile/authors/11344042tag:it.mathworks.com,2005:Question/52002011-04-10T22:43:30Z2021-04-10T17:00:21ZUndefined function or method '...' for input arguments of type 'double'.I'm getting the following error when I try to run some function m-files:
??? Undefined function or method '[name of function]' for input arguments of type 'double'.
I know this usually happens when the file isn't in the working directory, but that's not the case here.
When I was running these m-files in a different directory on my computer, it worked fine. I moved them to another directory on my laptop, and they're still fine, but I get this error on two of my desktops.
Thank you.Dhttps://it.mathworks.com/matlabcentral/profile/authors/1466466tag:it.mathworks.com,2005:Question/1621032014-11-10T16:40:05Z2021-04-10T16:58:54ZUndefined function for input arguments of type 'double'I have this set of data
x=[0:0.01:1];
y=4- 3*x + sin(x*6*pi) + rand(1,101)/8;
plot(x,y,'ko','MarkerFaceColor','k');
and want to do a fit using fminsearch
hold on
b0=[2,-2,2,5];
b=fminsearch(@(b) doamne(b,x,y), b0);
yfit= b(1)+ b(2)*x + b(3)*sin(x*pi*b(4));
plot(x,yfit, '-b')
hold off
where
function d2=doamne(b,x,y)
c2=y- (b(1)+ b(2)*x)
d2=sum(c2.^2)
but I keep getting this error: "Undefined function 'doamne' for input arguments of type 'double'."
I double checked that all my files are in the working folder and that the working folder is in the path list but the error persists.
Stefaniahttps://it.mathworks.com/matlabcentral/profile/authors/5833625tag:it.mathworks.com,2005:Question/7947722021-04-07T06:17:00Z2021-04-10T16:58:43ZHow to open and work with dicom images, which has no .dcm file extension. Errorusing dicom images. Unable to perform assignment because the size of the left side is 564-by-800 and the size of the right side is 564-by-800-by-1-by-56. This is the code.
img_folder = uigetdir;
dirOutput = dir(img_folder);
dirOutput([dirOutput.isdir]) = [];
filenames = fullfile(img_folder, {dirOutput.name});
file_num = length(filenames);
X = repmat(int16(0), [564 800 1 file_num]);
for y = 1:file_num
X(:,:,1,y) = uint16(dicomread(filenames{y}));
end
My images are ultrasound images with 564X800 diemesion. Any help is appreciated.MINO GEORGEhttps://it.mathworks.com/matlabcentral/profile/authors/18929086tag:it.mathworks.com,2005:Question/7982522021-04-10T15:46:01Z2021-04-10T16:55:25ZWhen creating a vector why does the size change when using a variable vs using a value?I am trying to create the time vector that starts at 0, has a step size of variable predefined (stepsize) and ends at predefined variable (fin_time).
In this case I calculated stepsize=0.0990 and fin_step=14.256
It would look like this time=[0:stepsize:fin_time]. When I type this I get a 144x1 vector.
When I type the value of stepsize manually. time=[0:0.0990:fin_time] I get a 145x1 vector. This is what I want.
How come the variable is exactly the same value but gives a different answer?Matt Thelenhttps://it.mathworks.com/matlabcentral/profile/authors/21447054tag:it.mathworks.com,2005:Question/7967322021-04-08T19:35:45Z2021-04-10T16:54:58Zappdesigner axes how to keep this part after change in axes
screenshot from appdesigner axes
as i am using dragable shapes in the axes, whenever i move something, the axes updates and i lose this selection area
how do i keep it there? Adrian Leehttps://it.mathworks.com/matlabcentral/profile/authors/11669489tag:it.mathworks.com,2005:Question/7981722021-04-10T13:44:22Z2021-04-10T16:54:26Zcontinuous piecewise linear approximation of data setI'll try to explain my problem: i'm studying the vertical profile of a railway. in a nutshell it's composed by a succession of straights and circles (tangents to the straights between which they are included). my data set is composed by survey points, measured along the railway with an uncertainty; my goal is to approximate this data set with a succession of straights and tangent circles (with the center on the bisector of the two straights in which it's included), such that certain constraints are respected (the most important concerns deviations, so i have to set lower and upper bounds).
I'm developing an algorithm that recognize (or try to) if the survey points belong to a straight or a circle (simply, computing of the change rate of gradient). after having cataloged all the points in the single lines and circles (i have the point group that belongs to the first straight, the point group that belongs to the second straights and the point group that belongs to the first circle, tangent to the first two straights.... and so on...). So, i need to approximate all the points groups that belongs to tangents with a continuous piecewise linear function, respecting lower and upper bounds constraints.
I've tried to write an algorithm using lsqlin for every single straight group points, but obviously the result is a discontinuous linear function whose vertices are not where I would like, i.e. included between the two groups of points belonging to the lines (so that i can then find the bisector and determine the center of the circle tangent to the two lines and that best approximates the survey points belonging to the circle). I hope someone has a good idea to join with mine to solve the problem in an elegant and general way.
Best Regardsalessio morabitohttps://it.mathworks.com/matlabcentral/profile/authors/8178855tag:it.mathworks.com,2005:Question/7983022021-04-10T16:52:34Z2021-04-10T16:52:34ZHow to plot 3D of 3D dataset and using evalfis function?Dear MATLAB users,
1- suppose I have a 3D dataset ([x, y, z]). In which the 'z' is the output and the x and y are the independent varaibels. How can I plot it? z is not an explicit function and suppise we've found z via experimentation. (I tried surf, mesh, plot3. But none of them worked).
2- Second question is, suppose that z will be generated using anfis function (.fis):
x = [];
y = [];
z = evalfis([x, y], readfis('... .fis')),
I need to plit it as well but I see problems/erros.
Any ideas?
Thanks Alireza Babaeihttps://it.mathworks.com/matlabcentral/profile/authors/17771320tag:it.mathworks.com,2005:Question/7982972021-04-10T16:52:06Z2021-04-10T16:52:06ZWriting complicated equations for problem-based optimizationI'm trying to solve a system of 16 non-linear equations, but don't know how to properly setup the optimization problem in Matlab.
While there are 16 variables that I am optimizing (a vector T, with entries i and scalar p), there are also intermediate parameters that are functions of the choice variables and model parameters (which are given).
variables and w are already model parameters. The actual equations to optimize are:
The code I have so far is
%Initial Variables
w = [0 2000 4000 6000 8000 10000 12500 15000 17500 20000 25000 30000 50000 100000];
w_dis_init = [.142 .033 .027 .028 .03 .048 .052 .065 .047 .082 .098 .164 .145 .039];
t_init = .4;
nit = 6000;
H = 5000;
v = 1;
%Elasticities
int_elast = .25*ones(1,length(w)); %zeta
ext_elast = zeros(1,length(w)); %eta
for(i=1:length(w))
if(w(i)<= 20000)
ext_elast(i) = .5
end
end
%Constructed Variables
T_init = (1-t_init)*w - nit;
c_init = w - T_init;
%Optimization Variables
T = optimvar('T',1,length(w));
p = optimvar('p',1);
c = zeros(1,length(w));
g = zeros(1,length(w));
h = w_dis_init;
%Optimization Equations
eq_c = c == (w-T);
eq_g = g == (p*c).^(-1);
eq_h = h == w_dis_init.*(c-c_init)/(c_init-c_init(1));
eq_hg = g.*h == 1;
eq_ht = h.*T == H;
I don't know if equations c,g, and h are how to properly code these laws of motion in MATLAB; I also don't know how to code the 14 equations governing T - my current best guess is to use a for loop to write out the 14 equations "manually" but I'm not sure.Brian Greenhttps://it.mathworks.com/matlabcentral/profile/authors/11520979tag:it.mathworks.com,2005:Question/7982822021-04-10T16:30:20Z2021-04-10T16:50:52ZBoolean operation of A not BHello guys,
I have 2 vectors "a" and "b" with b bigger than a. How can I create a new vector "c" with all the elements of b not in a.
Thank you in advanceAlcide Bertoccohttps://it.mathworks.com/matlabcentral/profile/authors/12604081tag:it.mathworks.com,2005:Question/4340322018-12-05T15:56:20Z2021-04-10T16:28:05ZSquare wave with values 0 to 1 rather than -1 to 1Hi,
I know that the square(t) function produces a wave with an amplitude from -1 to 1, is it possible to produce it from 0 to 1 instead?
ThanksMichael Au-Duonghttps://it.mathworks.com/matlabcentral/profile/authors/8735387tag:it.mathworks.com,2005:Question/7982722021-04-10T16:15:45Z2021-04-10T16:17:27ZTerminate while loop when user hits enterHi eveyone,
This is my while loop. It must end when user hits enter without entering a value . The loop allows for upto 3 successive blank entries before terminating. And, I cant get the n_points matrix to save entries without error.
How do I fix these?
Thank you for your time.
clear all
disp('Begin entering the data points')
t = 1;
x_point = input('enter x : ')
y_point = input('enter y : ')
n_points = [x_point,y_point];
while x_point ~= isempty(x_point) | y_point ~= isempty(y_point)
x_point = input('enter x : ')
y_point = input('enter y : ')
t = t+1
n_points(t,:) = [x_point,y_point]; % gives error ('Unable to perform assignment because the left and right sides have a different number of elements.')
endklbhttps://it.mathworks.com/matlabcentral/profile/authors/8181710tag:it.mathworks.com,2005:Question/7982772021-04-10T16:16:39Z2021-04-10T16:16:39ZHow to segment one row matrix into multiple row matrixHi, I do have for example this matrix [ 3 6 4 5 6 NaN 8 9 10 NaN NaN NaN 13 14 5 6 0 1 NaN NaN 2 3 NaN NaN NaN 9 1 5 NaN 2 8 NaN] and i would like to have matrix where each row would be each segment of values.
I mean like:
3 6 4 5 6
8 9 10
13 14 5 6 0 1
2 3
9 1 5
2 8Lukas Poviserhttps://it.mathworks.com/matlabcentral/profile/authors/16468382tag:it.mathworks.com,2005:Question/7908342021-04-02T11:45:15Z2021-04-10T16:15:49ZHow can i stitch different image to form one image and remove the error?Hello everyone,
I captured some images from of the one piece and i wanted to make a single image by stitching all images together. However, in the image stitching i am facing issues like
1)Previous Image strips does not match with next image strips, You can see the issue in image named as "Whole Picture issue". Can you guys tell me how to solve this error?
2)After removing the error, whole image in actual should be like this , you can see error free image named as "Whole Picture actual"
3)Name of the each image, You can see actual image named as "Whole Picture naming"
4)All separate images, You can see folder named as "Each pictures" to do perform stitching.
Can you guys tell me a code to remove this error and stitch all the images in the Matlab. Thanks a ton.
Dakota
Dakota Warnerhttps://it.mathworks.com/matlabcentral/profile/authors/22076288tag:it.mathworks.com,2005:Question/7982572021-04-10T15:48:15Z2021-04-10T16:03:45ZHow to solve an iteration problem for a formula in which there is the same variable on both sides (LHS and RHS)I have to solve this equation. In this equation, ∆i & s is an array and R is single variable. I need to find ∆i array using the s array and R constant. Using my scientific calculator, I was able to solve this equation, but i was not able to solve this formula. What should I do to perform iteration for each single element of array (converged values of ∆i for every single element of array).Buddha VijayGaneshhttps://it.mathworks.com/matlabcentral/profile/authors/18714495tag:it.mathworks.com,2005:Question/7982672021-04-10T16:03:28Z2021-04-10T16:03:28Zhelp to get input dataset
Design a neural network - back propagation (perceptron) that is able to recognize 3 different geometric figures: square, triangle and circuit (3 different patterns). We have randomly selected different geometrical figures as inputs, and in the output, the network should decide which pattern best fits the pattern figure.Ravi Rajhttps://it.mathworks.com/matlabcentral/profile/authors/21983007tag:it.mathworks.com,2005:Question/7980822021-04-10T11:13:09Z2021-04-10T16:02:12Z histogram style graph with several different data types with each type coloured differentlyI have a bunch of papers using different calculaton methords. I want to graph along the x axis the year the paper was published and on the y have boxes sized corrasponding to the number of papers of a given type published in that year where each type is coloured seperatly like a stacked bar chart. I have tried all manour of things and the closest thing I have got is this using a stacked bar chart but this is basically roated 90degrees from what I want (year on the x and number on the y with coloured boxes indicating type:
Oliver Nichollshttps://it.mathworks.com/matlabcentral/profile/authors/16284518tag:it.mathworks.com,2005:Question/219332011-11-22T14:08:45Z2021-04-10T15:59:19Zfinding root using false position methodGood evening\morning
I try to write a code that calculate the root of a nonlinear function using False Position Method,
but I get an infinite loop. I use the same loop for the Bisection Method and it's work.
clc
x0 = input('enter the value of x0 = ');
x1 = input('enter the value of x1 = ');
tolerance=input('inter the tolerance = ');
f =@(x) sin(2*pi*x)+ exp(1.2*x) + x - 2.5;
for i=0:inf
x2= x1 - (f(x1)* (x1-x0)/(f(x1)-f(x0)))
c = f(x2)
absolute_c= abs(c);
if absolute_c < tolerance
break
end
if f(x0)*c <0
x1=x2;
continue
else
x0=x2;
continue
end
end
i
Aydahttps://it.mathworks.com/matlabcentral/profile/authors/2862919tag:it.mathworks.com,2005:Question/7956022021-04-07T19:29:01Z2021-04-10T15:56:17Zcourbe de progression du pixelBonjour à tous j'ai en entrée 25 images IRM(dicom).
je metsen un point fixe (x,y) et je garde l'emplacement de ce pixel pour les autres images.
je veux tracer la courbe de progression de ce pixel. comment programmer ça?
Hello everyone, I have 25 MRI images (dicom) as input. I put a fixed point (x, y) and I keep the location of this pixel for the other images. I want to plot the progression curve of this pixel. how to program that?Amal Felhihttps://it.mathworks.com/matlabcentral/profile/authors/22103929tag:it.mathworks.com,2005:Question/7982072021-04-10T14:44:52Z2021-04-10T15:51:19ZHow to get only a part of the convhull line?Hi,
I have a problem with which I need support. I have a set of points in 2-D and using this set I would like to draw a line from points that are the closest to the left hand side of the graph. I tried to do so using the convhull command and that is what I got. Technically my problem is in this case - how to get only the left hand side of this quadrangle? Thank you in advance! :)Pawel Galinskihttps://it.mathworks.com/matlabcentral/profile/authors/17899771tag:it.mathworks.com,2005:Question/7982022021-04-10T14:43:12Z2021-04-10T15:45:46Zwhat is the problem with this code gauss siedel . Only processing one solution but it should be twenty solutionsclc
clear all
area=0.01; % Cross sectional area (m^2)
l=1; % Length of the rod (m)
k=5; % Thermal conductivity (W/mK)
g=20000; % Heat generation (W/m^3)
T1=100; % Temperature at one end (At x=0)
T2=500; % Temperature at the other end (At x=1m)
delta_x=0.05; % Cell spacing
n=20; % Number of cells
s= (k*area)/delta_x;
% Formulate the matrix form Ax=B
% Define matrix A
A=zeros(n,n);
A(1,1)= 3*((k*area)/delta_x);
A(20,20)=A(1,1);
A(2,1)= -((k*area)/delta_x);
A(20,19)=A(2,1);
% Define matrix B
B(1)=g*area*delta_x+2*s*T1;
B(2:19)=g*area*delta_x;
B(20)=g*area*delta_x+2*s*T2;
% For solution matrix x
x(1:n)=150; % Initial guess is taken as 150 at all nodes
normVal=Inf;
tol=1e-3; GaussItr=0;
plotGauss=[];
while normVal>tol
x_old=x;
for i=1:n
sigma=0;
for j=1:i-1
sigma=sigma+A(i,j)*x(j);
end
for j=i+1:n
sigma=sigma+A(i,j)*x_old(j);
end
x(i)=(1/A(i,i))*(B(i)-sigma);
end
GaussItr=GaussItr+1;
normVal=norm(x_old-x);
plotGauss=[plotGauss;normVal];
end
fprintf('Solution of the system is : \n%f\n%f\n%f\n%f\n%f in %d iterations',x,GaussItr);Sarvjeet Singhhttps://it.mathworks.com/matlabcentral/profile/authors/13298611tag:it.mathworks.com,2005:Question/7980672021-04-10T10:48:12Z2021-04-10T15:42:46ZCreate stand alone app without GUI?I have a simple Matlab script that selects a few Excel files from a given folder, reads-in the data and does some simple data processing saving the results in another Excel file. I select the folder with the needed files using uigetdir.
I've created a stand alone app for it, but when I run it nothing happens, I don't get the pop-up to select the folder with the files, I only get the splash screen. The app name appears in the Task Manager and stays there... What am I doing wrong?DChttps://it.mathworks.com/matlabcentral/profile/authors/1128911tag:it.mathworks.com,2005:Question/7975022021-04-09T14:28:35Z2021-04-10T15:37:23ZFind values that put equation to zeroIn this model:
where all the variables are of dymension TX1, I need to find all the (T) values of gamma that put the equation to zero.
I tryed with the following code, but the program returns me all NAN, how can I fix the code to get it?
j=1; %increment level. The loop will work for j>1 as well.
for i=1:j:T;
fnc = @(gamma,C,S) 1./(1+gamma).*(C(i)-(S(i)*gamma)) - M(i); % Model function
rn = @(gamma) norm(M - fnc(gamma,C,S)); % Residual norm
gamma0 = [15]; % Inizializzazione
[gamma, ResNorm] = fzero(rn, gamma0);
endMARCO FORTIhttps://it.mathworks.com/matlabcentral/profile/authors/16679691tag:it.mathworks.com,2005:Question/7977422021-04-09T19:47:23Z2021-04-10T15:36:38ZHow to Separate the RGB channels from an image and get the average of each RGB channel separetly How to Separate the RGB channels from an image and get the average of each RGB channel separately
Hello MATLAB community,
I have a set of 20 images, which I need to process simultaneously. All the images have a stain of red colourant in the middle, which I need to separate from the white background. I need to obtain the RGB value average of each channel (pixels) of the stained red area. I am new to the MATLAB world. Hence I am a bit unsure how to proceed. I leave an example of one of the images I have.
Thank you for your time. I appreciate all your help.Adriani Sierrahttps://it.mathworks.com/matlabcentral/profile/authors/16910730tag:it.mathworks.com,2005:Question/7980922021-04-10T11:24:31Z2021-04-10T15:35:47Zhow to read a data from text fileI want to read data from text file formatted as follows:
number 7 is the number of points and they are listed in form of (x y z).
_____________________________________________________________________________________________________________________________-
7
(
(-1.4330704e-08 2.9000119e-12 0)
(1.0601769e-06 -0.0001249935 0)
(1.0601769e-06 0.00012499351 0)
(-1.4330704e-08 2.9000119e-12 0.00016666667)
(1.0601769e-06 -0.0001249935 0.00016666667)
(1.0601769e-06 0.00012499351 0.00016666667)
(4.391607e-06 -0.00025131502 0)
)
____________________________________________________________________________________________________________________________________
how to exclude the first 2 lines and last one and only include numbers inside the brackets and export the as x,y and z arryzeinhttps://it.mathworks.com/matlabcentral/profile/authors/17514856