https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-04-22T00:13:34Ztag:es.mathworks.com,2005:Question/8093502021-04-21T23:31:29Z2021-04-22T00:13:34Zbuying a GPU for computer vision processingHello folks.
I have a low budget right now and im willing to buy an used R$ 650 (brazillian real) QUADRO P400 (2GB, 256core) or a unused GTX 1050TI (4GB, 768cores) - R$ 1700.
Both have 6.1 compute capability according to cuda sheet (CUDA GPUs | NVIDIA Developer) so i dont know if the GTX worth buying.
My project involve real time processing of 4 cameras: 2 small blobs identifications in two cameras (1 blob in each camera) and pose estimation in the two other cameras (2x1, stereo).
So far i can compute the blobs in real time (30fps) while the camera pose i havent calculated yet. Further, i havent used the gpu processing in my algorithm (matlab doesnt recognize my nvidia 6870) and I dont know much about it and if it will really improve processing.
Anyone can help me indicating what would be the best video card to my needs? Or tell me if the camera pose estimation can be easily processed in real time (30fps) with no gpu processing? i need 6dof of camera poseBicalhohttps://es.mathworks.com/matlabcentral/profile/authors/18324811tag:es.mathworks.com,2005:Question/268952012-01-24T02:42:22Z2021-04-22T00:12:36ZPoint cloud to Mesh/Surface/Grid to STLI have a data set of (x,y,z) coordinates for several points that form a point cloud in the form of the bones in a human leg. I want to use nearest neighbor interpolation of these points in order to create a grid and eventually an stl file to export to solid works.
Thanks
Isabellahttps://es.mathworks.com/matlabcentral/profile/authors/2562712tag:es.mathworks.com,2005:Question/4733252019-07-24T21:27:36Z2021-04-22T00:01:37ZHow to make errorbar transparent?How can I make a plot with discrete errorbar points which are transparent?
This thread did not contain an answer: https://www.mathworks.com/matlabcentral/answers/381188-how-to-define-transparency-of-errorbarsupernoobhttps://es.mathworks.com/matlabcentral/profile/authors/9462415tag:es.mathworks.com,2005:Question/8082602021-04-21T00:33:11Z2021-04-21T23:57:03ZError using gamfit . X must be non-negative.clear;clc
%hist = 'access05_indo_daily.txt'; % as x
%obs = 'chirps05_indo_daily.txt'; % as y
hist = 'hfeb_.txt'; % as x
obs = 'ofeb.txt'; % as y
delimiterIn = ' ';
%headerlinesIn = 1;
x = importdata(hist);
y = importdata(obs);
[m,n] = size(y);
ycor = zeros(m,n);
%cpolys = zeros(n,4);
xi = x(:,4);
yi = y(:,4);
yi(yi<=0) = 0;
Pxi = gamfit(xi);
Pyi = gamfit(yi(~isnan(yi)));
xgrid = linspace(0,1,101);
xinv = gaminv(xgrid,Pxi(1),Pxi(2)); xinv = xinv(1:100); % nilai ke 101 biasanya infinite value, jadi harus dibuang
yinv = gaminv(xgrid,Pyi(1),Pyi(2)); yinv = yinv(1:100); % nilai ke 101 biasanya infinite value, jadi harus dibuang
cpoly = polyfit(xinv,yinv,4);
%cpolys(i,:) = cpoly;Arly Getha Purbahttps://es.mathworks.com/matlabcentral/profile/authors/22274528tag:es.mathworks.com,2005:Question/8093152021-04-21T22:02:28Z2021-04-21T23:53:26ZHow to blank a grid value with a boundary file?I have a grid like the below:
[X, Y] = ndgrid([-180:0.25:179.75],[-90:0.25:89.75]);
Z = griddata(...); %on the same grid as X and Y
I also have a boundary file like the below (a lot more complicated in reality):
140 -5
140 -30
160 -30
160 -5
140 -5
How do I use the boundary file as above to only get the griddata (X1, Y1 and Z1) within the polygon and plot them onto a map as a contour like the below?
[C1, h1] = contourf (X1, Y1, Z1);
Leonhttps://es.mathworks.com/matlabcentral/profile/authors/3133287tag:es.mathworks.com,2005:Question/8028462021-04-15T09:12:49Z2021-04-21T23:51:16ZCombining 3-way-ANOVA of stratified bootstrapped datasetsI've the following situation:
i have a dataset which includes a head motion parameter for 16 different groups classified according to 4 different age groups and 4 different stimulus angles. one head motion parameter belongs to one trial and the 16 subgroups don't have equal number of trials (ranging from 21 to about 200). Each trial brings an onset error measurement with it.
I used stratified bootstrapping to generate 5000 'new' datasets, each having the same number of group members as in the original data set.
Now i want to run a 3-way-anova on each bootstrap data set. So here are 2 questions:
I was not sure if i need to rebalance the data set because the groups have different number of trials. At the moment I rebalanced the design of each bootrap data set by upsampling smaler groups and downsampling bigger groups to a size which equals the median of group sizes. I know that the function anovan() allows inbalanced input data, but does it compensate for it?
To run an ANOVA my intuition says that I have to run an ANOVA on each bootrap data set and combine the ANOVA results. How can this be done? Is it valid to take e.g. the mean of the p values?
I have attached a mat file which contains 3 variables, contains stimulus angle on the first column and age group number in the second column. The other two variables are 16x1 cells which contain 5000 bootrapped sets of the head motion paramter and the factor onset error. The design is already rebalanced to 123 trials per subgroup.
best regards
JonasJonashttps://es.mathworks.com/matlabcentral/profile/authors/7147967tag:es.mathworks.com,2005:Question/8093702021-04-21T23:46:48Z2021-04-21T23:46:48ZImage Segmentation - Image AnalysisI am working on segmenting B-mode ultrasound images and was hoping to get some advice on the problem below.
I am given an animation.avi file which contains 231 frames of 2D B-mode ultrasound images. The given task is to load each frame into matlab, make it a binary image, and segment the circular inclusion in the image. Ideally, I want to segment it to have a black background with a white circle corresponding to the lesion. My current attempt at doing this is given in the code below. The code itself is doing an ok job at isolating the white lesion from the background (attached image), but I was wondering if anyone had a better method to segment it from the background?
In addition, I want to take the white circular lesion from each frame and reconstruct a 3D image of the cylinder it forms. It has been suggested to me to use VolumeViewer in matlab, but was hoping to get some advice on how I could implement this too.
% Read the AVI file
% Find number of frames, video height, and video width
videoObject=VideoReader('animation.avi');
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
%Iterate through each frame
for frame = 1:numberOfFrames
currentFrame = read(videoObject, frame); % Reading current frame
hImage = subplot(1,2,1); % Create a subplot
image(currentFrame); % plot the current frame
caption = sprintf('Greyscale - Frame %4d of %d.', frame, numberOfFrames);
title(caption, 'FontSize', 22);
drawnow; % Force it to refresh the window.
BW = imgaussfilt(currentFrame, 8); % apply filter
BW = imbinarize(BW, 0.65); % make binary image using threshold
bwImage = subplot(1,2,2); % place next to original frame
image(BW);
caption = sprintf('BW - Frame %4d of %d.', frame, numberOfFrames);
title(caption, 'FontSize', 22);
drawnow; % Force it to refresh the window.
end
Matija Jankovichttps://es.mathworks.com/matlabcentral/profile/authors/17941795tag:es.mathworks.com,2005:Question/8093652021-04-21T23:45:56Z2021-04-21T23:45:56ZHow can I use a trained gaussian process inside a function to calculate predictions for the inputs of the function?I have a trained Gaussian Process regression on a set of data. I want to use this trained GP model inside another function to predict new outcomes whenever the function is called in another code, without having to train a GP model inside the function whenever it is called.
gpMdl=fitrgp(xtrn,ytrn); % this is the trained GP model
Now I want to use it for a function like following:
function Y=myfunc(Xnew)
yp=predict(gpMdl,Xnew); % predict based on the previously trained GP model
Y=1-exp(yp); % do something on the prediction and produce results
end
The function is then called somewhere else, for example:
% some code to give "some_data"
tp=some_data; % this is produced in the code
for i=numel(tp)
myfunc(tp(i));
endMohammad Moeinihttps://es.mathworks.com/matlabcentral/profile/authors/17454265tag:es.mathworks.com,2005:Question/8085352021-04-21T08:39:28Z2021-04-21T23:44:50ZExtract columns into new variables efficentlyHi Mathwork's community,
So I have a Matrix A such as:
A= [1 1 2 2 3 3 1 1 2 2 3 3; 1 1 2 2 3 3 1 1 2 2 3 3];
And a matrix B, which is the matrix that I'd like to separate into three different variables. (Note: There will always be three variables).
B = [10 20 30 40 50 60 70 80 90 100 110 120; 1 2 3 4 5 6 7 8 9 10 11 12];
Variable1 corresponds to B positions where A values are equal to 1, Variable2 corresponds to B positions where A values are equal to 2 and Variable3 corresponds to B positions where A values are equal to 3. The expected output should be:
Variable1 =[10 20 70 80; 1 2 7 8]
Variable2 = [30 40 90 100 ; 3 4 9 10]
Variable3 = [50 60 110 120; 5 6 11 12]
Could somone please help me out?
SantosSantos García Rosadohttps://es.mathworks.com/matlabcentral/profile/authors/18219488tag:es.mathworks.com,2005:Question/8093602021-04-21T23:42:38Z2021-04-21T23:42:38ZMake polar histogram bins on cardinal axes I am making a polar histogram showing eye movement directions. I would like each bin to represent each tick rather than representing the directions between the ticks. It is correct at 0, but incorrect at 90, 180, and 270, as shown here. How do I change it so that the bins represent cardinal directions at 0, 90, 180, and 270?
My code is very simple, the line is simply: "polarhistogram(saccade.AngularDirections,15)" where saccade is a table, and AngularDirections is a column of numbers with different directions in radians.
Thank you in advance! Stephanie Reeveshttps://es.mathworks.com/matlabcentral/profile/authors/19378051tag:es.mathworks.com,2005:Question/8093302021-04-21T23:05:43Z2021-04-21T23:38:08ZIndex in position 1 exceeds array bounds (must not exceed 641). Error in measurements (line 117) if m(xo,yo) ==0 I got the above error and I want to get the below output:
%%%% my code is:
close all
clear all
clc
xo=-16; yo=-16; %Map cooridnates
x=-13; y=-13; th=pi/2;
rr=1; %Robot radius
r=rr; %ray vector
n=3; %Number of sensors
dT=0.4;
dbstop if error
%%% My map
xw=-16; xe=16; ys=-16; yn=16; %map dimensions, west, east, south, north
mrx=0.05; mry=0.05; % map resolution {x,y}
[xm ym]=meshgrid(xw:mrx:xe,ys:mry:yn);
m=0*xm.*ym; % initialize the map m
for i=1:size(xm,2)
for j=1:size(ym,1)
r=sqrt(xm(1,i)^2+ym(j,1)^2);
ang=atan2(ym(j,1),xm(1,i))+pi;
if 9<=r && r<=10 && (pi/15<=ang && ang<=29*pi/15)
m(j,i)=1;
elseif 6<=r && r<=7 && ~(pi-pi/6<=ang && ang<=pi+pi/6)
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<-9 && -2.8<=ym(j,1) && ym(j,1)<=-1.8
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<-9 && 1.8<=ym(j,1) && ym(j,1)<=2.8
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<-13 && -2.8<=ym(j,1) && ym(j,1)<=14
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<-10 && 2.8<=ym(j,1) && ym(j,1)<=11
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<14 && 14<=ym(j,1) && ym(j,1)<=15
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<11 && 11<=ym(j,1) && ym(j,1)<=12
m(j,i)=1;
elseif 14<=xm(1,i) && xm(1,i)<15 && -15<=ym(j,1) && ym(j,1)<=15
m(j,i)=1;
elseif -5<=xm(1,i) && xm(1,i)<14 && -15<=ym(j,1) && ym(j,1)<=-14
m(j,i)=1;
elseif 10<=r && r<=16 && 0.95*pi/3.5<=ang && ang<=1.05*pi/3.5
m(j,i)=1;
elseif xm(1,i)<0.98*xw || 0.98*xe<xm(1,i) || ym(j,1)<0.98*ys || 0.98*yn<ym(j,1) % Boundaries
m(j,i)=1;
end
end
end
mesh(xm,ym,m); axis image; view(0, 90); %xlabel('x'); ylabel('y');
%%%%My control
t1=[0:dT:3]; % NOISELESS
u1=[0*ones(size(t1)); -1*ones(size(t1))];
t2=[0:dT:0.8]; % NOISELESS
u2=[1*ones(size(t2)); 0*ones(size(t2))];
t3=[0:dT:1.5]; % NOISELESS
u3=[0*ones(size(t3)); 1*ones(size(t3))];
t4=[0:dT:6]; % NOISELESS
u4=[1*ones(size(t4)); 0*ones(size(t4))];
t5=[0:dT:1.5]; % NOISELESS
u5=[0*ones(size(t5)); 1*ones(size(t5))];
t6=[0:dT:1.6]; % NOISELESS
u6=[1*ones(size(t6)); 0*ones(size(t6))];
t7=[0:dT:1.5]; % NOISELESS
u7=[0*ones(size(t7)); -1*ones(size(t7))];
t8=[0:dT:19]; % NOISELESS
u8=[1*ones(size(t8)); 0*ones(size(t8))];
t9=[0:dT:1.55]; % NOISELESS
u9=[0*ones(size(t9)); 1*ones(size(t9))];
t10=[0:dT:25.6]; % NOISELESS
u10=[1*ones(size(t10)); 0*ones(size(t10))];
t11=[0:dT:1.5]; % NOISELESS
u11=[0*ones(size(t11)); 0.98*ones(size(t11))];
t12=[0:dT:24]; % NOISELESS
u12=[1*ones(size(t12)); 0*ones(size(t12))];
t13=[0:dT:1.5]; % NOISELESS
u13=[0*ones(size(t13)); 0.98*ones(size(t13))];
t14=[0:dT:13]; % NOISELESS
u14=[1*ones(size(t14)); 0*ones(size(t14))];
t15=[0:dT:1.5]; % NOISELESS
u15=[0*ones(size(t15)); 0.98*ones(size(t15))];
t16=[0:dT:3.5]; % NOISELESS
u16=[1*ones(size(t16)); 0*ones(size(t16))];
t17=[0:dT:1.2]; % NOISELESS
u17=[0*ones(size(t17)); -0.94*ones(size(t17))];
t18=[0:dT:24]; % NOISELESS
u18=[1*ones(size(t18)); 1/8.2*ones(size(t18))];
t19=[0:dT:1.59]; % NOISELESS
u19=[0*ones(size(t19)); 1.01*ones(size(t19))];
t20=[0:dT:7.9]; % NOISELESS
u20=[1*ones(size(t20)); 0*ones(size(t20))];
u=[u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 u12 u13 u14 u15 u16 u17 u18 u19 u20]; % concatenate all controls into one
for t=1:2
v=u(1,t);
if u(2,t)~=0
w=u(2,t);
else
w=100*eps; % 100*eps because eps alone is too small, so causes division by zero problem
end
x=x-v/w*sin(th)+v/w*sin(th+w*dT);%state update
y=y+v/w*cos(th)-v/w*cos(th+w*dT);%state update
th=th+w*dT;%state update
subplot(1,2,1);
mesh(xm,ym,m); axis image; view(0, 90); hold on; xlabel('x'); ylabel('y');
plot(x,y,'ro','MarkerSize',10,'LineWidth',2); % DRAWS ROBOTs CIRCLE
plot([x; 1*r*cos(th)+x], [y; 1*r*sin(th)+y],'k-','LineWidth',2); % DRAWS BEARING
axis(16*[-1 1 -1 1]); drawnow; hold off;
%%%My measurement code
for k=0:n-1
th=th+2*pi*k/n;
xo=xo+r*cos(th); %corridnates(x,y) for the robot location
xo=((xo+16)/0.05)+1; xo=ceil(xo);
yo=yo+r*sin(th); %r is length(r)
yo=((yo+16)/0.05)+1; yo=ceil(yo);
if m(xo,yo) ==0 %if the location is not occupied
r=rr+0.05;
elseif m(xo,yo) == 1 %if the location is occupied
for kk=1:size(m,1)
subplot(1,2,2);
plot(m(kk,1) ,'b.'); axis(16*[-1 1 -1 1]); hold on;
end
end
end
end GHADAH AL-OBAIDIhttps://es.mathworks.com/matlabcentral/profile/authors/16891489tag:es.mathworks.com,2005:Question/8093552021-04-21T23:37:37Z2021-04-21T23:37:37ZUsing equationsToMatrix( ) with symbolic variables representing derivativesCurrently trying to put a system of equations into matrix form. There is a function y1 (function of x(t)) that is differentiated twice, and then a function y2 (function of z(t)) differentiated once. With these derivations, the chain rule is being applied, so the derivatives of the x and z variables are becoming present. For this example problem, after being differentiated, they should be put into a matrix as follows:
[A][x_ddot; z_dot] = [b]
where [A] is a 1x2 matrix of coefficients to x_ddot and z_dot, and [b] is the rest of the equation (function of other variables/derivatives of variables). Here is the current code:
syms t x(t) z(t) % define symbolic variables
y1 = x^3 % expression for y1 where x is a function of time
y1dot = diff(y1,t) % differentiation of y1
y1ddot = diff(y1dot,t) % differentiation of y1_ddot
eqn1 = 2*y1ddot == 4 % equation 1
y2 = z^4 % expression for y2 where z is a function of time
y2dot = diff(y2,t) % differentiation of y2
eqn2 = 3*y2dot == 17 % equation 2
eqns = [eqn1; eqn2] % system of equations to put into matrix form
vars = [sym(diff(x,2)); sym(diff(z,1))] % array of variables to sort each equation by in symbolic form
[A,b] = equationsToMatrix(eqns,vars) % equationsToMatrix expression
The expected output should look like this:
[6*x^2, 12z^3]*[x_ddot; z_dot] = [4-12*x*x_dot^2; 17]
I'm currently getting an error saying "Second argument must be a vector of symbolic variables." Is there a way to properly have the equationsToMatrix command use derivatives (like x_ddot and z_dot) to sort the matrices by? The syntax I used of sym(diff(x,2)) seemed to work for the built in isolate function, but not for thie equationsToMatrix.Matthew Frosthttps://es.mathworks.com/matlabcentral/profile/authors/15663379tag:es.mathworks.com,2005:Question/8090752021-04-21T16:58:39Z2021-04-21T23:20:50ZErrors while reading binary data filesI am trying to read binary files with uint32 data entries for example. The function reads the data correctly up to a certain elelment and then reads unexpected data (which I am sure do not exist in the original file). In some cases, these data blowup to very large values (for example, I was reading a uint32 data file with a maximum value of ~8000 and the maximum of data read is ~4.127*10^9. The code I am using is shown below (note: the asterisck does not have an effect, I repeated this with different files and checked the data using other programming languages/softwares):
function [X,Y,Z,Volume] = GetBin(filename,volumeSize,nOfBytes)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reads a binary formatted file into a 3D MATLAB matrix.
%
% INPUT:
% filename: string, name of binary file for reading
%
% OUTPUT:
% X,Y,Z: integer, size of matrix in cartesian coordinates
% Volume: integer 3D matrix, voxel values (labels)
% Ahmed Zankoor , April 2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file = "data\" + filename;
fid = fopen(file, 'rt');
if fid == -1
error('Cannot open file for reading: %s', file);
end
X = volumeSize(1);Y = volumeSize(2);Z = volumeSize(3);
% Read binary file, By default, fread reads a file 1,2 or 3 byte at a time,
% interprets one byte as an 8-bit unsigned integer (uint8),two byte as an 16-bit unsigned integer (uint16)
% three byte as an 32-bit unsigned integer (uint32).
if nOfBytes == 1
data = fread(fid,Inf,'*uint8');
data = uint8(data);
elseif nOfBytes == 2
data = fread(fid,Inf,'*uint16');
data = uint16(data);
elseif nOfBytes == 4
data = fread(fid,Inf,'*uint32');
data = uint32(data);
else
error('Unrecognized number of bytes per entry.')
end
fclose(fid);
if length(data)~= X*Y*Z
disp('Size of data does not match size of Volume.')
disp(['Size of data = ' num2str(length(data))])
disp(['Size of volume = ' num2str(X*Y*Z)])
end
Z = floor(length(data)/(X*Y));
data = data(1:X*Y*Z);
Volume = reshape(data,X,Y,Z);
end
For visualization, the image attached shows an example of the read data, where the top is correctly read data and then the mess below is because of the errors. I wonder if anyone knows why this may be happening?
Thank you.
Ahmed Zankoorhttps://es.mathworks.com/matlabcentral/profile/authors/12636478tag:es.mathworks.com,2005:Question/8093452021-04-21T23:16:20Z2021-04-21T23:16:20Zcolor area between two shapesI have two shapes and I want to color the area between them
The first shape is a circle of Radius R=10 for example and with center (0,0), and the second shape is a random shape but surrounds the cirle and may have communs points, but it is impossible to have points inside the circle (as in the picture).
As example for real data that I have:
load('data.m'); % load the coordinates of the second random shape represented as 'xfs' and 'yfs'
%%%%%%%%% create the circle %%%%%%%%%%
R = 10; C = [0. 0.] ;
xcf = C(1)+R*cos(linspace(0,2*pi,length(xfs))) ;
ycf = C(2)+R*sin(linspace(0,2*pi,length(xfs))) ;Khoder Makkawihttps://es.mathworks.com/matlabcentral/profile/authors/7417192tag:es.mathworks.com,2005:Question/4435142019-02-06T14:07:17Z2021-04-21T23:14:12ZWhy do I get this error 'Code generation does not support changing types through assignment' in Stateflow? I am implementing a logic using stateflow and I need to change the value of the input if one of the entry conditions get satisfied so as to not get caught in a loop. for example in the picture the inputs are color1 and color2 which are enums of the class Color. I am assigning color1 and color2 to temporary variables. Inside the subchart the first condition will be tested and if that is satisfied it will enter codn1 and assign the temporary variable with another value so that the condn2 can be tested. If the temporary variable is not used the input can't be assigned a value during simulation. The idea here is to assign values to a and b in the same simulation time. However I end up having this error if I initiate the inputs from MATLAB workspace:
This assignment writes a 'Color' value into a 'double' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches.
State 'Codn1'
"y1"
Figure1:
But this error doesn't occur if I initate the inputs inside the simulink file using constant blocks as shown in Figure 2.
Figure 2:
aparnasri sekarhttps://es.mathworks.com/matlabcentral/profile/authors/9319445tag:es.mathworks.com,2005:Question/8093402021-04-21T23:14:06Z2021-04-21T23:14:06ZLİcense file not foundwhen I want to update my license I recieve this error
Update failed because the application could not find a valid license file associated with license number #40790358; the license may have been deactivated on this machine previously.
Contact your system administrator if you need help. Alisan Okhttps://es.mathworks.com/matlabcentral/profile/authors/17744731tag:es.mathworks.com,2005:Question/8093352021-04-21T23:07:52Z2021-04-21T23:07:52ZSaving Multiple matlab files using print Hello
I am using this to save a multiple figures in ps format.
for i=1:14
print(figure(i), '-append', '-dpsc2', 'd:Myfigure.ps');
end
However, i would like to define the figure paper position, so when i use the code below, doent work :(
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperUnits','normalized');
set(h,'PaperPosition', [0 0 1 1]);
for i=1:14
print(gcf, figure(i), '-append', '-dpsc2', 'd:Myfigure.ps');
end
ANny help is appreciated. Also, can i save it directly to pdf instead of ps.
Thanksfriethttps://es.mathworks.com/matlabcentral/profile/authors/5876107tag:es.mathworks.com,2005:Question/8025962021-04-15T01:10:08Z2021-04-21T23:03:17ZReturning to a function and changing variables if ans is false?If someone can link me to a similar answer, I am sorry I could not find it.
I am calculating required beam depths to hold a certain load and I have an equation that tests a certain depth, and it must be less than the max strain allowed.
If my calculated value (Fs) is greater than what is allowed (Fs_max), how do I loop back to the equation and add a factor of 10 or so to the intital variable (dRound) so that it can run tests until it is <= max allowed?
Thanks.
if dRound > d
Fs_max = input('Enter max shearing force (Fs max) in MPa ');
V_max = W/2;
Fs = (3/2)*((V_max*10^3)/(b*dRound));
fprintf('Shearing force is = %f MPa\n', Fs);
end
end
if Fs > Fs_max
return ????Tim Kimhttps://es.mathworks.com/matlabcentral/profile/authors/22207998tag:es.mathworks.com,2005:Question/8093002021-04-21T21:19:08Z2021-04-21T22:59:33ZDot indexing is not supported for variables of this type.clear all
clc
sad = dir('D:\Project\DB1\test\'); % Returns both folders and files
cell_array_of_folder_names = {sad([sad.isdir]).name}; % Select folder names
cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
sorted_cell_array_of_folder_names = sort_nat( cell_array_of_folder_names );
%----------------
[mp1, np] = size(sorted_cell_array_of_folder_names); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
for i=1:mp1
%% keep only folders:
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
if isempty(strfind(sorted_cell_array_of_folder_names(i).name,'.'))
csf1 = csf1 +1; % one sub folder found
SFN = sorted_cell_array_of_folder_names(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
IM=imread([PF SFN '\' tifFileName]);
%t=1;
%for i=1:csf1
% for j=1:ms1
Group_Test1(t)={i-2};
t=t+1;
end
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName);
end
save('Group_Test','Group_Test1');
%----------------------
Dot indexing is not supported for variables of this type.
Error in Untitled2 (line 15)
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
>> sun risehttps://es.mathworks.com/matlabcentral/profile/authors/16482360tag:es.mathworks.com,2005:Question/5090322020-03-04T17:57:49Z2021-04-21T22:55:43ZHow to read numerics as strings with readtable?I have a table in spreadsheet (xlsx). One of the column is composed of either a numerical number, or several of them, like the below:
2
3
5,7
9
7
4
2,8,9
5
When I use readtable:
T1 = readtable ('Observations.xlsx');
the results are like this:
2
3
NaN
9
7
4
NaN
5
My question is how do I read the info as a string, so that the groups like '5,7', and '2,8,9' are all captured?
I tried:
T1 = readtable ('Observations.xlsx', 'Format','%s %s %s');
But got the below error:
Invalid value for "Format". Must be "auto" for spreadsheet files.Leonhttps://es.mathworks.com/matlabcentral/profile/authors/3133287tag:es.mathworks.com,2005:Question/560712012-12-08T14:47:21Z2021-04-21T22:46:26Zhow can i do huffman encoding in image compressionhi,i am doing lossy image compression using discrete cosine transform i had done all the steps of the compression(dct then quantization then zigzag scan) now i have a vector and i want to do huffman encoding i know that the code as follows
[dict,avglen] = huffmandict(symbols,p)
comp = huffmanenco(sig,dict)
i am asking now how to get the symbol and p(probability) from the large vector that i have to do the encoding omarhttps://es.mathworks.com/matlabcentral/profile/authors/3910003tag:es.mathworks.com,2005:Question/5932452020-09-14T07:48:20Z2021-04-21T22:45:17ZFind the value of the number LaTeX: a a such that the families of curves LaTeX: y=\left(x+c\right)^{-1} y = ( x + c ) − 1 and LaTeX: y\:=\:a\left(x\:+\:k\right)^{\frac{1}{3}} y = a ( x + k ) 1 3 are orthogonal trajectories. Find the value of the number a such that the families of curves y=(x+c)−1and y=a(x+k)13 are orthogonal trajectories.
im trying to write htis on matlab to have it solved can you help me Mauricio Alvarezhttps://es.mathworks.com/matlabcentral/profile/authors/13850091tag:es.mathworks.com,2005:Question/8093052021-04-21T21:37:20Z2021-04-21T22:43:36ZError using plot: vectors must be the same lengthsI am trying to plot two function in the same file; however, I am getting the following error: "Error using plots: vectors must be the same lengths". The rest of the code works. The only problem in in the plotting. I can plot them individually, but I cannot plot them together. Please help me to find a way to do this. Here is my code:
clear; clc;
% Definition of all variables and functions
% Stock price
variance = 1; % Variance
average = 0; % Average
t = 10000; % Time
stock_value(1) = 200; % Initial stock value
% Delta hedging
K = 200; % Strike price
r = 0.05; % Risk free interest rate
sigma = 0.4; % Volatility of asset
tau = 1; % Time constant
d1(1) = (1/sigma*sqrt(tau))*(log(stock_value(1)/K)+(r+(sigma^2)/2)*tau);
N(1) = normcdf(d1(1));
delta(1) = exp(-r*tau)*N(1);
for j=2:t
% Monte Carlo somulation of stock price
stock_value(j) = stock_value(j-1) + randn*variance;
if stock_value(j) > 1
variance = 0.5;
elseif stock_value < -1
stock_value = 2;
else
variance = 1;
end
% Delta hedging
d1(j) = (1/sigma*sqrt(tau))*(log(stock_value(j)/K)+(r+(sigma^2)/2)*tau);
% Cumulative normal distribution
N(j) = normcdf(d1(j));
% Delta
delta(j) = exp(-r*tau)*N(j);
end
% Plots
x = linspace(0,t);
y1 = stock_value;
y2 = delta;
tiledlayout(2,1)
% Top plot
ax1 = nexttile;
plot(ax1,x,y1)
title(ax1,'Stock Value')
ylabel(ax1,'S_t')
% Bottom plot
ax2 = nexttile;
plot(ax2,x,y2)
title(ax2,'Delta to Maturity')
ylabel(ax2,'delta_t')
% Show results
% Stock value
fprintf('initial stock value =%.8f\n',stock_value(1))
fprintf('stockvalue at first quarter =%.8f\n',stock_value(t/4))
fprintf('stockvalue at second quarter =%8f\n',stock_value(t/2))
fprintf('stockvalue at third quarter =%.8f\n',stock_value((3*t)/4))
fprintf('final stockvalue =%.8f\n',stock_value(t))
% Delta
fprintf('initial delta =%.8f\n',delta(1))
fprintf('delta at first quarter =%.8f\n',delta(t/4))
fprintf('delta at second quarter =%.8f\n',delta(t/2))
fprintf('delta at third quarter =%.8f\n',delta((3*t)/4))
fprintf('delta at maturity =%.8f\n',delta(t))Anthony Knightonhttps://es.mathworks.com/matlabcentral/profile/authors/17159993tag:es.mathworks.com,2005:Question/8093252021-04-21T22:40:12Z2021-04-21T22:42:29ZLoad shifting code neededI have been working on DSM these days and i am pretty new in this sector I don't know how to write a code in matlab to reduce peak load and shift the extra load it to a new slot.
Can a kind hearted person help me in that case by providing the code Or provide me the right path to follow?
Thanks!Md.Akramul Khandakarhttps://es.mathworks.com/matlabcentral/profile/authors/22266033tag:es.mathworks.com,2005:Question/8093202021-04-21T22:09:13Z2021-04-21T22:42:28ZLatitudes and longitudes of mouseclick in openstreetmap.How can I get latitudues and longitudues of mouseclick in openstreetmap?. Is it possible? I tried inputm but it doesn't work or I did something wrong.Damian Godlewskihttps://es.mathworks.com/matlabcentral/profile/authors/18250523tag:es.mathworks.com,2005:Question/3868412018-03-07T11:11:07Z2021-04-21T22:41:34ZHow to Convert .wav file into binary? load handel.mat
filename = 'handel.wav';
audiowrite(filename,y,Fs);
clear y Fs
[y,Fs] = audioread('handel.wav');
sound(y,Fs)
I want to use the following code to convert the .wav audio file into binary. Which MATLAB command should be used for converting .wav file in to binary?
TIA.Asra Khalidhttps://es.mathworks.com/matlabcentral/profile/authors/12326038tag:es.mathworks.com,2005:Question/8090302021-04-21T16:13:04Z2021-04-21T22:40:33ZThe array size.What is the FWHM of the central core Sinan Elishahttps://es.mathworks.com/matlabcentral/profile/authors/7505725tag:es.mathworks.com,2005:Question/8037212021-04-16T06:31:06Z2021-04-21T22:31:44ZHow to animate the change in a variable with respect to date and time in matlab?I have an excel file with date, time and depth columns. I want to animate the change in the depth from the start of the date to the end along with time running in the display. The time is also showing in decimal number instead of the hh:mm:ss format. Can anyone please help me with this? Niraj Bal Tamanghttps://es.mathworks.com/matlabcentral/profile/authors/17627635tag:es.mathworks.com,2005:Question/8089252021-04-21T14:22:43Z2021-04-21T22:23:06Zi'm getting an error that inputs should be scaler on "t=linspace(0,t_flight,30);" v0=app.InitialvelocityEditField.Value;
y0=app.InitialheightEditField.Value;
theta=app.InitialangleEditField.Value;
g=app.gEditField.Value;
x0=0;
b=v0*sin(pi*(theta/180));
a=-g/2;
c=y0;
t_flight=(-b-sqrt(b^2-4*a*c))/(2*a);
t_flight=app.FlighttimeEditField.Value;
range=v0*cos(pi*(theta/180))*t_flight;
range=app.DistancetraveledEditField.Value;
t=linspace(0,t_flight,30);
xdot0=v0*cos(pi*(theta/180));
ydot0=v0*sin(pi*(theta/180));
m_y=y0+(v0.^2)*(sin(pi*(theta/180)))^2/(2*g);
m_y=app.maximumheightEditField.Value;
x=x0+xdot0*t;
y=y0+ydot0*t-(g/2)*t;
plot(app.UIAxes,x,y)
legend(app.UIAxes,'projectile')Mahmoud Chawkihttps://es.mathworks.com/matlabcentral/profile/authors/21374663tag:es.mathworks.com,2005:Question/8090202021-04-21T15:57:35Z2021-04-21T22:21:20ZCODES ON MATLAB: DIGITAL SIGNAL PROCCESSING (REGRESSION MODEL FOR EMG)% Learning phase
======================================================================
Nb_wind = 30; % size of calculation windows
load Data_EMG_Regression.mat % or any EMG_DATA
============================comments===========================
We have a file :
%Content of the Data_EMG_Regression.mat
% "Data_EMG_mat_all" EMG are data from 8 channels
% - "Traget_X_Y" the movements in X and Y of the wrist which
% are estimated from EMG signals. The first column represents the values in X and the second column represents the% valuesin Y
% - fs is the sample rate for signals above 200Hz… fs=200
%====================================================================
Question 1
How to add the time vector to the curves and plot figure (1) with name to the axes x and y?
Question 2
How to calculate Calculate the frequency spectrum of the Data_EMG_mat_all signal
Question 3
How to Draw the figure (2) which shows the frequency spectrum of the signal Data_EMG_mat_all with the x-axis in frequency
Question 4
How to Build and apply a filter on the Data_EMG_mat_all signal which ensures that there is no electrode movement in the EMG signals. Knowing that the output of the filter will have the same name as its input. Meanining build a filter above 20 hz to take out the electrode (elec)
Question n ° 5
How to Draw the figure (3) which shows the frequency spectrum of the signal Data_EMG_mat_all which is now filter. Question Numbers 2 and 3 should allow to confirm the operation of your filter.
Question # 6
How to calculate the MAV_feat and VAR_feat, using the following loop for the discriminating criteria (features) for each of the EMG filter signals. Using those matlab code
- the calculation of MAV_feat (the mean absolute value)
- the calculation of VAR_feat (the variance of the signal)
======================== Extraction of features ===========================
for n = 1:size(Data_EMG_mat_all,1)-Nb_wind
for elec = 1:8
temp = [];
temp = Data_EMG_mat_all(n:n+Nb_wind-1,elec);
%%%- RMS
RMS_feat(n,elec) = rms(temp);
%%% - Wavelength (WL) (Wavelength - WL)
WL_feat(n,elec) = sum(abs(temp(1:end-1,1)-temp(2:end,1)));
%- % - Mean Absolute Value (MAV) (Mean Absolute Value - MAV)
Answer matlab code here!
MAV_feat(n,elec)=...
%- Variance
Answer matlab code here!
VAR_feat(n,elec) = ...
end
end
Question # 7
How to draw the figure (4) which presents 4 curves one below the others and each curve must present the features according to the calculation windows.
Question # 8
% Gathering of features and Normalization
% ===================================================================
Q.8.a. How to Build a vector called “Feature” which groups together the 4 discriminating criteria. We must make sure that the Feature dimension must be of total number of calculation windows by the total number of features.
Q.8.b. How to Calculate the mean (Mean_val) and variance (Var_val) of the Features matrix. We must make sure that the dimension of these two vectors must be 1 by the number of features
Q.8.c. How to apply the normalization calculation on the Feature matrix above
Q.8.d. How to Construct the Target vector from Traget_X_Y… We have to make for that Traget_X_Y has the same row count as Feature.
Q.8.e. How to Draw on figure (5), 3 curves one below the other. We have to make sure the first must present target in X, the second the target in Y and the third the features.
mapad222https://es.mathworks.com/matlabcentral/profile/authors/11462724tag:es.mathworks.com,2005:Question/8092352021-04-21T19:29:51Z2021-04-21T22:21:10Zcreating a GUI with edit box and push buttonHi,
I need to write a code that will create a editable text box and I have a few questions about it
How and where to insert a function that will place my text into 5 lines?
Here's my code and the output is an error :
I think there are a lot of things to modify so I would really appreciate your help :
clc;clear all; close all;
figures=figure()
global text
set(gcf,'CurrentAxes',figures.Children)
%button.Callback=@testoccurences2;
button = uicontrol('Style','pushbutton','String','Count Letters','Position',[50 50 300 75]);
editbox=uicontrol('Style','edit','String','0','Position',[200 200 100 100]);
editbox.Callback=@ (src,evt)entertext
button.Callback=@(src,evt) get_occurences(text);
function[]=entertext()
global text
prompt={'Enter poem'};
text=inputdlg(prompt);
end
function[]=get_occurences(String)
vect_A=[];
i=1;
for letter=String(1:length(String))
letter=lower(letter);
for alphabet=['a':'z']
A=count(String,alphabet);
vect_A(i)=A; %stock the value
i=i+1;
end
end
occ_table=array2table(vect_A);
occ_table.Properties.VariableNames = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
end
When the user presses the button, a table needs to show up, with the alphabet and the nu;ber of occurences of each letter in the text Noa Prasquierhttps://es.mathworks.com/matlabcentral/profile/authors/21741252tag:es.mathworks.com,2005:Question/8092602021-04-21T19:45:54Z2021-04-21T22:20:03ZDifference between switch and ifI just ran across switch being used in a code and am wonder how it differs from if. The use of switch may not have been well set up in the code I was looking at, because they look generally the same. I did not read the documentation in great detail, just enough to get an idea of what switch does.Bob Thompsonhttps://es.mathworks.com/matlabcentral/profile/authors/7983890tag:es.mathworks.com,2005:Question/8092902021-04-21T20:52:45Z2021-04-21T22:10:33ZAdd row to an empty array if a condition is fulfilledHi everyone,
I have a 5 x 3 array and I have to make a code that checks row by row if the third column fulfills a condition. (In this case, the third column should be equal to the letter "A").
When there's an "A" in the third column, I have to take all that row and place it in a new array and this new array should have all the rows that fulfill the condition.
Mariel Cristohttps://es.mathworks.com/matlabcentral/profile/authors/22140467tag:es.mathworks.com,2005:Question/8091202021-04-21T17:48:15Z2021-04-21T22:09:51Zcollide Two particles with each otherhey friends
i have a problem with an issue.
i would like to program two particles(circle) that come close to each other and then check them if they have in contact with each other or not.
and finally plot these process.
--------------------------------------------
u=r1+r2-d
"u" is a whole distance
"d" is a distance from center to center two circles
"r1" is the radius of first circle and "r2" is the radius of second circle
if "u" is negative, two circles have contact and vice versa...
***************************************
would you mind please help me?hadi mehttps://es.mathworks.com/matlabcentral/profile/authors/22283975tag:es.mathworks.com,2005:Question/4128892018-07-31T10:38:28Z2021-04-21T22:04:05ZPlot an interpolated plane in between two planesI have two ground truth depth images (image 1 and image 2) which are located at different distances (150 cm and 203 cm) from the camera. Both the depth images are perpendicular to the camera. I am uploading here the original images.
I'd like to get a middle image by interpolation which will be in between these images (see the illustration).
Illustration:
<</matlabcentral/answers/uploaded_files/127175/illus.png>>
To do that, I have first cropped the object from the images and then planning to use scatteredinterpolant function to get the interpolated plane in between these two images. However, I am struggling how exactly should I define the interpolation to get the interpolated plane.
I have attached here the depth images and the cropped images and a bit of codes which I did so far.
Any suggestions?
_Note: I already have a middle ground truth depth image which is located at 178 cm. I need the interpolated plane so that I can compare the accuracy of the ground truth image with the interpolated plane/surface._
thresholdValue = 10;
originalImage1 = imread('depth_153.png');
originalImage2 = imread('depth_203.png');
binaryImage1 = originalImage1 > thresholdValue;
binaryImage2 = originalImage2 > thresholdValue;
EdgeMeasurements1 = regionprops(binaryImage1, originalImage1, 'all');
EdgeMeasurements2 = regionprops(binaryImage2, originalImage2, 'all');
croppedImage1 = imcrop(originalImage1, EdgeMeasurements1.BoundingBox);
croppedImage2 = imcrop(originalImage2, EdgeMeasurements2.BoundingBox);
x = 1:size(croppedImage1,1);
y = 1:size(croppedImage1,2);
[X,Y] = meshgrid(x,y);
Tariqulhttps://es.mathworks.com/matlabcentral/profile/authors/13223760tag:es.mathworks.com,2005:Question/8088502021-04-21T13:00:13Z2021-04-21T22:01:03ZPutting Screenshots from Videos into an ArrayI have a set of 3 videos and would like to take four screenshots from each one at the same times (ie. frames) to put into a 3x4 array of images, what would be the easiest way to do this on MATLAB?
The files are saved both as .avi and .cihx files from a high-speed video camera.Hollis Williamshttps://es.mathworks.com/matlabcentral/profile/authors/9712150tag:es.mathworks.com,2005:Question/8084552021-04-21T06:45:14Z2021-04-21T21:53:25ZRunge-Kutta 2Hi, i have a homwork for school including the Runge-Kutta 2.
I have to do it in symbolic, i would be very greatfull if someone can help me in this taks.
intervalmin = 0;
intervalmax = 1;
h1 = 0.1;
g = 0.02;
X0 = [0, 0];
[t1, x1] = fuggveny(intervalmin, X0(1), X0(2), h1, intervalmax);
[t2, x2] = fuggveny(intervalmin, X0(1), X0(2), g, intervalmax);
syms x(t);
dz = diff(x,t);
ode = diff(x,t,2) + 5.*diff(x,t,1) + 4.*x(t) == 3 - 2.*t - t.^2;
cond1 = x(0) == 1;
cond2 = dz(0) == 1;
RK2(t) = dsolve(ode,cond1,cond2);
plot(t1, x1, '-y');
hold on;
plot(t2, x2, '--r');
hold on;
fplot(RK2,'-*b');
hold on
legend('h=0.1','h=0.02','ode')
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
grid on;
function dX = f(t, x1, x2)
X1 = x2;
X2 = -5.*x2 + 4.*x1 + 3 - 2.*t - t.^2;
dX = [X1, X2];
end
function [t, x] = fuggveny(intervalmin, X0_1, X0_2, h, intervalmax)
t = (intervalmin:h:intervalmax);
X1 = zeros(size(t));
X2 = zeros(size(t));
X1(1) = X0_1;
X2(1) = X0_2;
for i = 1:1:length(t) - 1
k1 = f(t(i), X1(i), X2(i));
k2 = f(t(i) + h/2, X1(i) + h/2 * k1(1), X2(i) + h/2 * k1(2));
k3 = f(t(i) + h, X1(i) - h*k1(1) + 2*h*k2(1), X2(i) - h*k1(2) + 2*h*k2(2));
X1(i + 1) = X1(i) + h/6 * (k1(1) + 4*k2(1) + k3(1));
X2(i + 1) = X2(i) + h/6 * (k1(2) + 4*k2(2) + k3(2));
end
x = X1;
endNagy Csaba Norberthttps://es.mathworks.com/matlabcentral/profile/authors/19523272tag:es.mathworks.com,2005:Question/8081772021-04-20T21:52:20Z2021-04-21T21:46:44ZHow to display the actual values of my percentages on a pie chart Hello everyone, this is a basic question for many of you and I would really appreciate if you can take the time and explain to me: How to display the actual values of my percentages on a pie chart and How to display percentage and labels on the pie chart.
TotalNumberOfCars = 75;
White = 34;
Black = 19;
Red = 12;
Silver = 2;
Grey = 3;
Other = 5;
% simple percentage
Per_White = White/ TotalNumberOfCars * 100
Per_Black = Black / TotalNumberOfCars * 100
Per_Red = Red / TotalNumberOfCars * 100
Per_Silver = Silver / TotalNumberOfCars * 100
Per_Grey = Grey / TotalNumberOfCars * 100
per_Other = Other/TotalNumberOfCars * 100
% The results 45.333, 25.333, 16, 2.666, 4
%I missed up somewhere
X = [34 19 12 2 3 5];
pie (X)
Labels = { 'White' , 'Black' , 'Red' , 'Silver' , 'Grey', 'Other'};
pie(X, Labels)
%I also tried to make the percentages as a vector
Y = [45.333, 25.333, 16, 2.666, 4];
pie(Y)
which produce mismatched percentages
Aladdinhttps://es.mathworks.com/matlabcentral/profile/authors/14477943tag:es.mathworks.com,2005:Question/8092752021-04-21T20:21:37Z2021-04-21T21:45:50ZHow to draw a rectangle over a patch? Hello, I need to draw a rectangle with curved edges over a background that I created using patch(). For the rectangle I am using the function rectangel() because it has a curvature property. I know that other functions have a property like 'layer' that lets me place things on top of others, but rectangle() doesn't have this property. I am open to alternative methods of creating the rounded rectangle or the background so that I can get the final result.
Thanks in advance! Nathaniel Levi Blankhttps://es.mathworks.com/matlabcentral/profile/authors/18439214tag:es.mathworks.com,2005:Question/8093102021-04-21T21:42:42Z2021-04-21T21:42:42ZShare String Data with Custom C CodeThe topic “Share String Data with Custom C Code” in the help, describes only the exchange of "strings" that were defined in Simulink.
But if I must use externally defined strings, I haven't found an efficient way yet.
I currently help myself with a helper function in C, which copies a selected string into a Simulink variable. But to my eyes this is only a "workaround"!
So in the C - module (with the strings) I added the function Get_MyCString:
static char Txt1[] = "Hello!";
static char Txt2[] = "You";
// more strings
extern void Get_MyCString(unsigned char* Cstr, unsigned int No)
{// Cstr: Simulink variable; No: C - String number
unsigned char *S; //source
unsigned char *D; //destination
switch (No)
{// select C string
case 1:
S = Txt1;
break;
case 2:
S = Txt2;
break;
// more strings
default:
S = "C string number doesn't exist!";
}
// copy string into Simulink variable
D = Cstr;
while (*S)
{
*D++ = *S++;
}
}
and in Stateflow a function getCstr:
Is there no way to assign externally defined strings directly to Simulink (Stateflow) variables??!Tom Poltzhttps://es.mathworks.com/matlabcentral/profile/authors/10388717tag:es.mathworks.com,2005:Question/8086302021-04-21T09:51:02Z2021-04-21T21:38:51ZHow to classify images depending on the shape of each image's object ?Mohamed Elbeialyhttps://es.mathworks.com/matlabcentral/profile/authors/11449960tag:es.mathworks.com,2005:Question/8092852021-04-21T20:51:48Z2021-04-21T21:33:38ZWhat's the value of Ki in PD controller?I designed PD controller and got Kp and Kd.
When I use feedback command like feedback(sys*pid(Kp,Ki,Kd),1), what value should I write for Ki?Hwajin Choihttps://es.mathworks.com/matlabcentral/profile/authors/17222447tag:es.mathworks.com,2005:Question/8036262021-04-16T03:18:51Z2021-04-21T21:25:09ZHelp with iteration convergence.So I have a system of equations that I need to iterate until convergence.
I've tried doing this with for loops, while loops, symbolicly, and lastly using approximation methods.
Maybe convergence doesnt mean what I think it means, maybe I'm just missing something.
Here is my code...
clear all; close all; clc;
%% Given Data.
T = 20000; % lb
rho = .002377; %slug/ft^3
A = 2827; % ft^3
v_tip = 650; % ft/sec
R = 30; %ft
a = 6; % Lift Curve Slope
Theta_Tw = -10*pi/180; % Radians Twist Rate
gamma = 8.1; % Blade Lock
Cd0 = 0.01;
Sigma = 0.085;
k = 1.15;
mu = linspace(0.05,0.3,26); % Advance Ratio
i_hp = [-10; 0; 10]*(pi/180); % Radians
phi_hp = 0; % Lateral Shaft Tilt
beta1C = 0;
beta1S = 0;
%% Derived Data.
Omega = v_tip/R; % Rad/sec
% Thrust Coefficient of Main Rotor During Trimming Process
CT = T/(rho*A*v_tip^2);
% Constant for Flapping Equations
delta = 1-mu.^2+9*mu.^4/4;
% Initial Conditons
lambda_i_initial = [sqrt(CT/2), CT./(2*mu(2:end))];
% Convergence Equations
lambda = mu.*tan(i_hp)+lambda_i(1,:);
lambda_i = CT./(2*(mu.^2+lambda.^2));
I need to take the initial solution for lambda_i and insert that into the equation for lambda, and then take the lambda solution and insert it into lambda_i, then lambda_i into lambda and so on until convergence.
Any help would be appreciated.Terry Poolehttps://es.mathworks.com/matlabcentral/profile/authors/12282800tag:es.mathworks.com,2005:Question/8088352021-04-21T12:47:02Z2021-04-21T21:18:55Zhow to make it into for loopHello,
I am trying to make the below cose into a for loop
Would you help me with that?
file1=load('0.txt','-ascii');
a=file1(:,1);
b=file1(:,2)-r_peak1(1)/1000;
c=file1(:,3);
data=[a,b,c];
save('0.txt','data1','-ascii');
file2=load('3.txt','-ascii');
a=file2(:,1);
b=file2(:,2)-r_peak1(2)/1000;
c=file2(:,3);
data=[a,b,c];
save('3.txt','data1','-ascii');
file3=load('6.txt','-ascii');
a=file3(:,1);
b=file3(:,2)-r_peak1(3)/1000;
c=file3(:,3);
data=[a,b,c];
save('6.txt','data1','-ascii');
file4=load('9.txt','-ascii');
a=file4(:,1);
b=file4(:,2)-r_peak1(4)/1000;
c=file4(:,3);
data=[a,b,c];
save('9.txt','data1','-ascii');
Thank youarthur doroshevhttps://es.mathworks.com/matlabcentral/profile/authors/9158385tag:es.mathworks.com,2005:Question/3447362017-06-14T12:49:06Z2021-04-21T21:18:46ZDatastore - support for mat-filesI am trying to use the tall array functionality to sort a very large table, as well as other calculations. The tables are currently stored in several mat-files. When trying to create a datastore object to be used as input to the tall arrays, using one or more mat-file as inputs does not seem to be possible.
Am I missing something? Do I have to export the data to some other format to use as input for the datastore object? Any input would be appreciated. MSTKhttps://es.mathworks.com/matlabcentral/profile/authors/2302524tag:es.mathworks.com,2005:Question/297702012-02-21T11:52:51Z2021-04-21T21:17:10ZQuestion: subplot axes label cut off (activepositionproperty problem?)Hi! I want to make a subplot such that two plots are side by side. The resulting figure needs to be small enough to fit in my document, and in the eps format. However, when I try to resize the figure past a certain size, the axes x labels are cut off like so :
<<http://i.imgur.com/aV2FF.jpg>>
this only happens when you resize it small enough. Also, it doesn't happen with the 'plot' command, I can resize as much as i like and the axes labels are maintained in the figure. My understanding is that activepositionproperty governs this sort of thing, and that it should be set to 'outerposition', but I've tried forcing that and it doesn't have any effect. Also, it doesn't seem to matter if you manually set the papersize and paperposition and then export, or whether you change the figure size using WYSIWYG on screen and then exporting. Would be grateful for any ideas to work around or fix this problem! I'm sure it didn't used to happen on earlier versions of matlabPaul Bhttps://es.mathworks.com/matlabcentral/profile/authors/3337980tag:es.mathworks.com,2005:Question/7186602021-01-16T16:59:29Z2021-04-21T21:17:08Z-If else- conditionals in matlab app.designer?I have a doubt about conditionals on matlab app.designer.
For example in this litlle and simple app. I have defined a private variable F which value is 60.
The point here is that, when I select the "ac" option in the dropmenu below, and click the button, the number 1917 appears on the white box
This is the conditional I have designed to occur that, and doesn't work. The question is that if the option of the dropmenu is only a letter (for instance 'a' or 'b' or whatever, it does work. But when the option is one or more characters, like in the example below, it doesn`t work and appears the following error.
How it is possible that the code above works perfectly when I have only one letter but does not when are two or more characters?
Thank you very much!ErikJon Pérez Mardarashttps://es.mathworks.com/matlabcentral/profile/authors/15826364tag:es.mathworks.com,2005:Question/8045412021-04-17T04:22:41Z2021-04-21T21:16:08ZVariable 'Group_Test1' not found.clear all
clc
sad = dir('D:\Project\DB1\test\'); % Returns both folders and files
cell_array_of_folder_names = {sad([sad.isdir]).name}; % Select folder names
cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
sorted_cell_array_of_folder_names = sort_nat( cell_array_of_folder_names );
%----------------
[mp1, np] = size(sorted_cell_array_of_folder_names); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
for i=3:mp1
%% keep only folders:
P = strfind(sorted_cell_array_of_folder_names(i).name,'.');
if isempty(strfind(sorted_cell_array_of_folder_names(i).name,'.'))
csf1 = csf1 +1; % one sub folder found
SFN = sorted_cell_array_of_folder_names(i).name ;% extract his name
tifList = ls(sprintf('%s%s%s%s',PF,SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
IM=imread([PF SFN '\' tifFileName]);
%t=1;
%for i=1:csf1
% for j=1:ms1
Group_Test1(t)={i-2};
t=t+1;
end
end
PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName);
end
save('Group_Test','Group_Test1');
%----------------------sun risehttps://es.mathworks.com/matlabcentral/profile/authors/16482360tag:es.mathworks.com,2005:Question/8092952021-04-21T21:13:06Z2021-04-21T21:13:06Zargument of type "int64_t" is incompatible with parameter of type "int64m_T" - Static code metrics error reportHello,
We are trying to build the environment for our simulink model . While trying to generate code, one of the interface of int64 datatype ( in Simulink model) is getting generated in code as int64m_T (supposed to be int64_T). Would someone suggest any workaround how to get in generated code as int64_T in this case? We tried force typecasting inside the function but not helpful in achieving int64 datatype.
Also we found this is occuring with Hardware Device Type Infineon->TriCore. (In Intel->x86-64 (Windows64) it is generated as int64_T). Please find the error report below.
Vijayabharathi Jhttps://es.mathworks.com/matlabcentral/profile/authors/18978541tag:es.mathworks.com,2005:Question/8059762021-04-18T21:08:00Z2021-04-21T21:08:53ZResume from latest Randstream Hi,
I am generating some data with matlab over azure. While generating data I use rand.
x = x_limits(1) + rand*(x_limits(2)-x_limits(1));
z = z_limits(1) + rand*(z_limits(2)-z_limits(1));
I usually generate a couple of MB of data (~200k samples) which I then use and perform tests on and then depending on the results from the test I generate more. However I have encountered a problem which is that when starting the script for generating data again It gives me the exact same as the previous generated data file. Even if I use:
rng('shuffle')
I still get a data file containing a lot of the same data. Is there a way in which I can save where my randstream finsihed in a lets say randState.mat file that I can later call when resuming data generator. Basically, picking up where the randstream last was used.
Thanks! Sebastian Thunéhttps://es.mathworks.com/matlabcentral/profile/authors/21982058