https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-09-30T06:39:00Ztag:it.mathworks.com,2005:Question/6023322020-09-30T06:35:50Z2020-09-30T06:39:00ZCan I convert matrix to system equation?Can I convert matrix to system equation?If I want to input matrix A=[4 -4 0;2 3 5;3 5 7] X=[x1;x2;x3] B=[4;5;6]Thnchhttps://it.mathworks.com/matlabcentral/profile/authors/18436957tag:it.mathworks.com,2005:Question/6018402020-09-29T09:46:02Z2020-09-30T06:38:12ZHDL FIFO and (not so) algebraic loop errorsHi everyone, thanks for checking in on my question.
What I am trying to do is build a sorting network based on mergesort. For every sorting step I use a HDL FIFO Block to store the sorted results. The next sorting node will compare the outputs of wo fifos and togehter with some additional logic decide which value to forward. The corresponding fifo from the layer will be poped according to this decision. Therefor I loop back the pop from one stage to the previous stage.
This lead to an algebraic loop error in his pop signal. I could resolve this by use of an delay, but it will destroy the sorting. I was able to somehow resolve this error for my test setup, but after migrating the concept to my special problem, I could not get it to work again. Do you have any Ideas which settings might be involved in this error, that I might tweak to get it running?
I am sure, that actually there should not be an algeraic loop in the model at all, therefor I have trouble understanding what is going on.
Greetings and thanks in advance
Edit:
Uploaded the software here: https://www.mathworks.com/matlabcentral/fileexchange/80578-sorter-to-sort-4-presorted-datasetsFlorian Rössinghttps://it.mathworks.com/matlabcentral/profile/authors/19120177tag:it.mathworks.com,2005:Question/6023292020-09-30T06:35:15Z2020-09-30T06:37:52Zfixed point Iterative method for finding root of an equationThe code below gives the root and the iteration at which it occur. The code goes into an infinite loop when the function contains any logarithmic or exponential function. But works fine with algebraic and trignometric function.
% f = @(independent variable) simplified eqation example:- f = @(x) (5x+7)^(1/3)
function [root,iteration] = fixedpoint(a,f) %input intial approiximation and simplified form of function
if nargin<1 % check no of input arguments and if input arguments is less than one then puts an error message
fprintf('Error! Atleast one input argument is required.');
return;
end
if nargin<2 % check no of input arguments and if input arguments is less than two then puts a=0
a=0;
end
x(1) = f(a) ;
i =1 ;
temp = false;
while temp == false
x(i+1) = f(x(i));
if x(i+1) == x(i)
temp = true;
root = x(i-1);
iteration = i-1;
return;
end
i = i +1 ;
end
x
end
Milind Amgahttps://it.mathworks.com/matlabcentral/profile/authors/13867031tag:it.mathworks.com,2005:Question/6006222020-09-27T07:36:01Z2020-09-30T06:36:50ZHow can I find three nodes voltage for the following electrical circuit problem?
Find out
can you write a function that will return these node voltages if you input values of V and resistances
N.B: the function should return valid mentioned node voltages even if you input any resistance = 0.
This is a coursera problem
Mastering Programming with MATLAB, Week-3, electrical circuit problem
link:
https://www.coursera.org/learn/advanced-matlab-programming/gradedLti/0tPA5/problem-1-electrical-circuits
Khokon Chandra Sazzalhttps://it.mathworks.com/matlabcentral/profile/authors/19222748tag:it.mathworks.com,2005:Question/6023262020-09-30T06:30:34Z2020-09-30T06:36:14ZHow to terminate ODE at particular point?I have defined this ODE as function qd2=odefcn2(t2,q2)
where t2=pi/4:0.5:pi/2; and q2=[ [q12;q22;q32];
after running above ODE I am getting result as
4.1706 9.2403 1.5708
4.2743 9.3530 1.5707
4.3779 9.4658 1.5705
4.4816 9.5785 1.5704
4.5853 9.6912 1.5703
4.6889 9.8040 1.5701
4.7926 9.9167 1.5700
4.8963 10.0294 1.5699
4.9999 10.1422 1.5697
5.1036 10.2549 1.5696
5.2073 10.3676 1.5695
5.3109 10.4804 1.5693
5.4146 10.5931 1.5692
5.5183 10.7058 1.5691
5.6219 10.8186 1.5690
5.7256 10.9313 1.5688
5.8293 11.0440 1.5687
5.9329 11.1568 1.5686
6.0366 11.2695 1.5684
6.1402 11.3822 1.5683
6.2439 11.4950 1.5682
6.3476 11.6077 1.5680
6.4512 11.7204 1.5679
6.5549 11.8332 1.5678
6.6586 11.9459 1.5676
6.7622 12.0586 1.5675
6.8659 12.1714 1.5674
6.9696 12.2841 1.5672
7.0732 12.3969 1.5671
7.1769 12.5096 1.5670
7.2806 12.6223 1.5668
7.3842 12.7351 1.5667
7.4879 12.8478 1.5666
7.5916 12.9605 1.5664
7.6952 13.0733 1.5663
7.7989 13.1860 1.5662
7.9026 13.2987 1.5660
8.0062 13.4115 1.5659
8.1099 13.5242 1.5658
8.2136 13.6369 1.5657
8.3172 13.7497 1.56
these are total 41 rows ,if i want to stop at q(30,:) what is the matlab code for this?
thank yousangita kamathttps://it.mathworks.com/matlabcentral/profile/authors/5990114tag:it.mathworks.com,2005:Question/5992182020-09-24T15:36:45Z2020-09-30T06:30:29ZHow to save Simulink model without model workspace saved I have a Simulink model named “input_check.slx” and I want to load model parameters loaded from an external .mat file. After I run the model (out = sim(‘input_check’);), I want to save the model to the file of same name without its parameters in model workspace saved and close the system ‘input_check’. For some reason, I want the model workspace cleared when I close system so I set 'SaveModelWorkspace' = false
load_system('input_check')
hws = get_param('input_check', 'modelworkspace');
hws.DataSource = 'MAT-File';
hws.FileName = 'slx_input_check_pars.mat';
hws.reload; %reload variable from an external file to model workspace
out = sim('input_check')
save_system('input_check',[],'SaveModelWorkspace',false)
close_system('input_check')
load_system('input_check')
hws = get_param('input_check', 'modelworkspace');
After I save and close the model I load the system and get the model workspace (last two lines in code) and figure out the data source for model workspace is still there and is the .mat file I loaded earlier. I think set ‘SaveModelWorkspace’ = False should clear the model workspace but obviously not. What cause this issue? Also if I want to save the model to the file of same name without its parameters in model workspace saved, am I doing correctly?
Matlab Version is R2020a. Hainan Wanghttps://it.mathworks.com/matlabcentral/profile/authors/13874724tag:it.mathworks.com,2005:Question/4601502019-05-03T21:11:23Z2020-09-30T06:29:36ZWrite a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnufunction charnum = char_counter(fname,character)
fid = fopen(fname, 'rt');
if fid < 0
count = 0;
else
fid = fopen(fname,'rt');
oneline = fgets(fid);
l=length(oneline);
count = 0;
while ischar(oneline)
for i = 1:l
if strcmp(oneline(i),character)
count = count+1;
end
end
oneline = fgets(fid);
l=length(oneline);
end
end
if count == 0
charnum = -1;
else
charnum = count;
end
Saurabh Kumarhttps://it.mathworks.com/matlabcentral/profile/authors/14200402tag:it.mathworks.com,2005:Question/5909082020-09-09T04:12:58Z2020-09-30T06:28:36ZHow to extract Best fitness graph for Genetic Algorithm in Matlab after each optimization run?I have run my GA in Matlab. But I didn't save the Best fitness graph during the optimization run. I did save the optimization result as .mat file. My questions are;
1. Is it possible for me to extract and plot the Best fitness graph by using the optimresult/optimprob/options of the .mat file after the GA run has finished? How to extract the graph?
2. Did the Best fitness graph can only appear during the optimization run?
Thank you for your response.Yushazaziah MohdYunoshttps://it.mathworks.com/matlabcentral/profile/authors/18929671tag:it.mathworks.com,2005:Question/6023142020-09-30T05:21:45Z2020-09-30T06:26:29ZHow to use 'drawnow' to create an animated surface plot from audio measurements taken in a matrix of 10 x 10 microphone positionsI am attempting to code for an animated surface plot of audio data.
The measurements were taken in ten steps of ten channels to create a 10 x 10 matrix of microphone measurement positions, and so 100 resultant recordings of equal length.
In principle, I want each value in a 10 x 10 x Z(ampliude) surface plot to be "fed" by data from an audio vector, whether sample by sample or at increments (every 100th sample, for example); whatever balances computational efficiency with satisfactory visualisation. So, position x = 1, y = 1 in the "new"/empty matrix (that will become the animated plot) will be "fed" values from its corresponding audio recording. Basically, the plot should redraw itself for each sample (or sample increment) of the 100 recordings.
So far, I think using the 'drawnow' function call is the way to go, but I'm not sure where to go from here. Do I need to create 100 'for' loops; one for each position in the animated matrix?
I'm at the very start of figuring this out, so have no code to show. I hope I've managed to explain what I'm trying to achieve. Thanks in advance for any help anyone may be able to provide.
Cheers!Peter Beringerhttps://it.mathworks.com/matlabcentral/profile/authors/17669911tag:it.mathworks.com,2005:Question/6001962020-09-26T05:57:23Z2020-09-30T06:22:52ZHelp for my probel in Firefly Algorithm for PSS, in fitness particle is not run
%% -------------------------------------------------------- %
%% Bismillaahirrahmaanirrahiim %
%% Firefly Algorithm
%%--------------------------------------------------------- %
clc
%Parameter PSS
Ks=20;
T1=0.02;
T2=0.05;
T3=3;
T4=5.4;
T5=2;
%% Parameter of FireFly
% Td1 Td2 Td3 Td4 Td5 Td6
Ub=[5 25 1 1 5 5.5]; % Batas atas parameter
Lb=[0.5 0 0 0 0 0]; % Batas bawah parameter
etol=10e-5;
% Inisialisasi acak
u0=(Lb+Ub)/2; ns=zeros(20,6);
% Algorithm's parameters
%para=[n MaxGeneration alpha betamn gamma]
%para=[20 50 0.35 0.20 1]
% n = Jumlah kunang-kunang
% MaxGeneration = Jumlah iterasi
% ------------------------------------------------
% alpha=0.25; % Nilai acak 0--1
% betamn=0.20; % Nilai beta minimum
% gamma=1; % Koefisien absorbsi
% ------------------------------------------------
n=10; MaxGeneration=5;
alpha=0.35; betamin=0.2; gamma=1;
% Menghitung dimensi pencarian kunang-kunang
d=length(u0);
%Inisialisasi awal kandidat solusi
for ikj=1:n
ns(ikj,:)=Lb+(Ub-Lb).*rand(1,d); % Kolom = Dimensi, dan Baris = FireFly
end
% Inisialisasi nilai fitness sebelum evaluasi
Lightn = ones(n,1);
% Looping Evaluasi algoritma kunang-kunang
hfig = figure(1);
hold on
title('Behaviour of FireFly Algorithm Graphic');
set(hfig, 'position', [50,40,600,300]);
set(hfig, 'DoubleBuffer', 'on');
hbestplot = plot(1:MaxGeneration,zeros(1,MaxGeneration),'-');
xlabel('Iteration');
ylabel('Fitness Function');
hold off
drawnow;
kq=1;
while kq<=MaxGeneration
% start iterasi
%Menghitung nilai alpha yang baru
delta=1-(0.005/0.9)^(1/MaxGeneration);
alpha=(1-delta)*alpha;
%Evaluasi fungsi fitness (untuk semua kunang-kunang)
for ikj=1:n
Ks_FF = ns(ikj,1);
T1_FF = ns(ikj,2);
T2_FF = ns(ikj,3);
T3_FF = ns(ikj,4);
T4_FF = ns(ikj,5);
T5_FF = ns(ikj,6);
sim('SkripsiKu')
t1=f.time;
y1=f.signals.values;
for i=1:800
error(i)=t1(i)*abs(y1(i));
end
ee_itae=sum(error);
fitness_particle(ikj)=ee_itae;
zn(ikj) = fitness_particle(ikj);
Lightn(ikj) = zn(ikj);
end
% Merangking kunang-kunang berdasarkan intensitas cahaya
% masing-masing
[Lightn,Index]=sort(zn);
ns_tmp=ns;
for ikj=1:n
ns(ikj,:)=ns_tmp(Index(ikj),:);
end
%% Mencari kunang-kunang yang terbaik
nso=ns; Lighto=Lightn;
nbest=ns(1,:); Lightbest=Lightn(1);
% Gerakkan semua kunang-kunang ke lokasi yang lebih baik
% Faktor skala pada sistem
scale=abs(Ub-Lb);
% Mengupdate posisi kunang-kunang
for ikj=1:n
% Parameter Attractiveness Kunang-Kunang : beta=exp(-gamma*r)
for jkj=1:n
r=sqrt(sum((ns(ikj,:)-ns(jkj,:)).^2));
% MengUpdate Pergerakan kunang-kunang
% Apakah lebih terang dan attractive
if Lightn(ikj)>Lighto(jkj)
beta0=1; beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin;
tmpf=alpha.*(rand(1,d)-0.5).*scale;
ns(ikj,:)=ns(ikj,:).*(1-beta)+nso(jkj,:).*beta+tmpf;
end
end % akhir untuk j
% Konstraint
for irg=1:3
if ns(ikj,irg)<=Lb(irg)
ns(ikj,irg) =Lb(irg) ;
elseif ns(ikj,irg)>=Ub(irg)
ns(ikj,irg) =Ub(irg);
end
end
end % akhir untuk i
plotvector=get(hbestplot,'Ydata');
plotvector(kq)=Lightn(1);
set(hbestplot,'Ydata',plotvector);
drawnow
kq=kq+1;
end %%Akhir Iterasi
Ks_FF = nbest(1);
T1_FF = nbest(2);
T2_FF = nbest(3);
T3_FF = nbest(4);
T4_FF = nbest(5);
T5_FF = nbest(6);
% FF.m
% Displaying FF.m.Satrio Wicaksonohttps://it.mathworks.com/matlabcentral/profile/authors/12268927tag:it.mathworks.com,2005:Question/4837262019-10-05T15:20:28Z2020-09-30T06:21:53Zplot(x,y(1,:) meaningHi,
I'm new matlab. I was wondering what the y(1,:) means?
I have ran this code: plot(x,y(1,:),'r-o',x,y(2,:),'g*','LineWidth',2) and can't make sense of the 1 and 2 in regards to the y coordinate.
ThanksChloehttps://it.mathworks.com/matlabcentral/profile/authors/16445505tag:it.mathworks.com,2005:Question/6011802020-09-28T10:15:55Z2020-09-30T06:19:36ZCode take forever to run and outputHI, when i was running my code, only the first 2 figure shown up (Figure 1 and Figure 2), the others are not showing up. I run the code and leave it for more than an hour but only the first 2 figure shown up. The code run for more than an hour to run and it does not output the rest of the figures. May I know what are the problems?
codes:
clear all; close all; clc
%Read and display source image
imgA = imread('test1.jpg');
imgA = rgb2gray(imgA);
figure(1); imshow(imgA); title('Image from Source');
%Convert source image to Grayscale
imgB = imread('test2.jpg');
imgB = rgb2gray(imgB);
figure(2); imshow(imgB); title('Image from Intensity');
%Make both images the same size
%Get the size of image A
[rowsimgA colsimgA numberOfColorChannelsimgA] = size(imgA);
%Get the size of image B
[rowsimgB colsimgB numberOfColorChannelsimgB] = size(imgB);
%Check if lateral sizes match
if rowsimgB ~= rowsimgA || colsimgA ~= colsimgB
imgB = imresize(imgB, [rowsimgA colsimgA]);
end
imgA = im2double(imgA);
imgB = im2double(imgB);
error = 468;
iteration = 1100;
image_void = fftshift(imgB);
image_void = ifft2(image_void);
image_void = fftshift(image_void);
%Decompose into amplitude and phase (image is converted into double)
for i=1:iteration
if error>464
image_fft_recon = abs(imgA) .* exp(1i*angle(image_void));
image_recon = fftshift(image_fft_recon);
image_recon = fft2(image_recon);
image_recon = fftshift(image_recon);
image_fft_recon2 = abs(imgB) .* exp(1i*angle(image_recon));
image_void = fftshift(image_fft_recon2);
image_void = ifft2(image_void);
image_void = fftshift(image_void);
%RMSE Error
error = [error; (1/sqrt(rowsimgA*colsimgA)*sqrt(sum(sum(abs(image_recon)-abs(imgB)).^2)))];
else
g=1;
break;
end
end
fprintf('No. of iterations required to meet the error threshold is %i\n',i)
figure (5)
i = 1:1:length(error);
plot(i,(error'));
title('Error');
grid on
% Verification of amplitude and phase values
C1=abs(image_fft_recon./image_fft_recon);
C2=imgA./imgA;
if 'C1=C2'
disp ('Pixel Locations where the amplitude is non-zero the phase has a value')
else
disp('answers not verified')
end
figure(3);
imagesc(abs(image_void)),colorbar;
title('exponential img');
figure(4);
imagesc(abs(image_fft_recon)), colorbar;
title('constructed img');
phase_image=(abs(image_fft_recon));
figure(6),plot(phase_image), title('Phase diagram');Soong Wei Kanghttps://it.mathworks.com/matlabcentral/profile/authors/18480833tag:it.mathworks.com,2005:Question/6006162020-09-27T07:09:31Z2020-09-30T06:18:20ZDifferent size error bar capsI wish to make a bar chart with 5 bars with error bars on only two of these bars. My current code is
bounds=categorical({'aa','bb','cc','dd','ee'});
vals=[1,2,3,4,5]
set(gca,'TickLabelInterpreter','latex','Fontsize',18);
ylabel('Variance','Fontsize',20)
%
% pause(2)
colors = [0 0 1;
1 0 0;
1 0 0;
0 1 0;
0 1 0];
alphas = [1,0.3,1,0.3,1];
b = gobjects(size(bounds));
cla()
hold on
for i =1:numel(bounds)
b(i)=bar(bounds(i),vals(i));
if rem(i,2)==0
line='--';
else
line='-';
end
set(b(i),'FaceColor',colors(i,:),'FaceAlpha',alphas(i),'LineStyle',line);
end
ehigh=[0,0.5,0,0.8,0]
elow=ehigh;
hold on
er = errorbar(bounds,vals,elow,ehigh,'k','LineStyle','none');
er.Color = [0 0 0];
er.LineStyle = 'none';
er.LineWidth=1;
er(1).CapSize=20;
which almost does what I want, however I can still see the zero error bar in the three bars with no error. I can get rid of this by setting the capsize to 0 but I don't really want this as then I have no caps on the error bars that I do want. Is there a way to set the error bar cap sizes differently for each point?
Or equally good would be a way to only have error bars on certain bars.
Many thanks!!Lorcan Conlonhttps://it.mathworks.com/matlabcentral/profile/authors/13794866tag:it.mathworks.com,2005:Question/4897002019-11-06T05:00:00Z2020-09-30T06:16:36ZIs MATLAB compatible with macOS Catalina?Does MATLAB support macOS Catalina (10.15)?
MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813tag:it.mathworks.com,2005:Question/6008562020-09-27T18:34:28Z2020-09-30T06:16:00Zhow could we identify the type of blur in an image?? first, how could we realize that a image is blurred or not???how could we identify an image is blurred or not and the type of blur occured??
if i create a blur to an image by fspecial(), can we see the matrix of psf??
is it possible to simulate a blur only to a particular object(portion) in an image, if so how??
can someone help me with the code too for better understanding.
Thanks in advance.....Vimal Rajhttps://it.mathworks.com/matlabcentral/profile/authors/13867939tag:it.mathworks.com,2005:Question/6021972020-09-29T22:35:29Z2020-09-30T06:15:29ZFourier Series for a Periodic FunctionWhy is the graph not complete?
%% Problem 1_Example_17.2
display('Problem 1_Example_17.1')
ao=1/4;
an=[1/[(n^2)*(pi^2)]]*((1-(-1)^n));
N = 100000;
Wo = pi;
t = -1:.001:11;
f = zeros(1,length(t));
for n = 1:2:N
bn = (-1)^n+1;
f = f + an*cos(Wo*n*t) + bn*sin(Wo*n*t);
end
% Plotting and plot formatting is done here
plot(t,f)
axis([-1 11 -1.1 1.1])
title(['Fourier Series Representation w/ ' num2str(N) ' Terms'],'FontSize',16)
xlabel('Time')
ylabel('Function Value')Salik Mallickhttps://it.mathworks.com/matlabcentral/profile/authors/16029915tag:it.mathworks.com,2005:Question/6016662020-09-29T02:49:12Z2020-09-30T06:15:00ZFast subsetting or indexing of dataI am working with large datasets which I am subsetting into various categories and saving as smaller files. What I am doing right now is working but it is quite time consuming and error prone, as it involved a lot of copy and paste.
For example, I have many files I have split into those with boats and those without boats. I then split those into season. Would there be a faster way to do this where I apply the same command to prescribed set of variables?
%% Comparisons... Season using water temp
boatsAbsent_t=boatsAbsent.Var1; %time variables
[BA_spring, BA_summer, BA_autumn, BA_winter]=indexSeasons(boatsAbsent_t); %index times into seasons
boatsPresent_t=boatsPresent.Var1;
[BP_spring, BP_summer, BP_autumn, BP_winter]=indexSeasons(boatsPresent_t);
%Subset PSD outputs and write to file
S=withtol(BA_spring,seconds(1));
BA_spring=boatsAbsent(S,:);
writetable(timetable2table(BA_spring),...
fullfile(folder,strcat(site,'_PSD_boatsAbsent_Spring.csv')));
S=withtol(BA_summer,seconds(1));
BA_summer=boatsAbsent(S,:);
writetable(timetable2table(BA_summer),...
fullfile(folder,strcat(site,'_PSD_boatsAbsent_Summer.csv')));
S=withtol(BA_autumn,seconds(1));
BA_autumn=boatsAbsent(S,:);
writetable(timetable2table(BA_autumn),...
fullfile(folder,strcat(site,'_PSD_boatsAbsent_Autumn.csv')));
S=withtol(BA_winter,seconds(1));
BA_winter=boatsAbsent(S,:);
writetable(timetable2table(BA_winter),...
fullfile(folder,strcat(site,'_PSD_boatsAbsent_Winter.csv')));
S=withtol(BP_spring,seconds(1));
writetable(timetable2table(BP_spring),...
fullfile(folder,strcat(site,'_PSD_boatsPresent_Spring.csv')));
S=withtol(BP_summer,seconds(1));
writetable(timetable2table(BP_summer),...
fullfile(folder,strcat(site,'_PSD_boatsPresent_Summer.csv')));
S=withtol(BP_autumn,seconds(1));
writetable(timetable2table(BP_autumn),...
fullfile(folder,strcat(site,'_PSD_boatsPresent_Autumn.csv')));
S=withtol(BP_winter,seconds(1));
writetable(timetable2table(BP_winter),...
fullfile(folder,strcat(site,'_PSD_boatsPresent_Winter.csv')));Louise Wilsonhttps://it.mathworks.com/matlabcentral/profile/authors/15959472tag:it.mathworks.com,2005:Question/6023232020-09-30T06:14:39Z2020-09-30T06:14:39ZHow to segment tumour region from lung ct image using Super pixel density based algorithm.Krishna Pavanhttps://it.mathworks.com/matlabcentral/profile/authors/18076193tag:it.mathworks.com,2005:Question/6022902020-09-30T03:57:14Z2020-09-30T06:13:05Zcan you explain the SUPER PIXEL DENSITY BASED REGION SEGMENTATION METHOD ?This is the segmentation method
i understood how to get superpixelized image by SLIC algorithm but i am strucked in applying SUPER PIXEL DENSITY BASED REGION (SPDBR) algorithm to get output of this . so can u explain how the method works shankara chttps://it.mathworks.com/matlabcentral/profile/authors/17089313tag:it.mathworks.com,2005:Question/6023022020-09-30T04:39:16Z2020-09-30T06:07:19ZCalculating displacement, power, energy and torque from velocity data in .csv format.I have to find the displacement, power, energy and torque from a data that contains velocity of an object over time. The velocity and time data is in csv format. Could you please take a look and let me know if the results are correct? I'm a bit unsure about the energy one. How to use the 'integral ' command for this?
clc
A=csvread(' data .csv'); %reads csv data (';' prevents this from printing into the screen)
t=A(:,1);
time_hr=A(:,1)*3600; % sec to hr
speed=A(:,2)*1.60934; %miles to km
%Finding average speed:
avg_speed=mean(A(:,2))/10^3
% dist vs. time graph:
displacement=avg_speed.*time;
%plotting accln
dV=gradient(speed/10^3);
dt=0.01;
Accln=dV./dt;
figure(1)
subplot(3,1,1)
plot(t,displacement)
title('displacement')
subplot(3,1,2) % m*n grid, p position
plot(t,speed) %plot speed vs. time
title('speed')
subplot(3,1,3)
plot(A(:,1),Accln)
title('Acceleration')
%------------------------------------------------------%
%Power Calculation:
%Step 1: Force Calculation
mass=1257;
Fa=mass*Accln;
% subplot(4,1,4)
% plot(A(:,1),Fa)
% title('Force')
Power=Fa.*speed;
% Torque calculation:
Torque=Fa*0.1778*1.1;
%Energy calculation
%Energy=integral(Power,0,A(:,1));
Energy=cumtrapz(Power);
figure(2)
subplot(3,1,1)
plot(A(:,1),Power) % plot power
title('Power')
subplot(3,1,2)
plot(A(:,1),Torque)
title('Torque')
subplot(3,1,3)
plot(A(:,1),Energy/1000)
title('Energy')Siddhi Kadamhttps://it.mathworks.com/matlabcentral/profile/authors/13213064tag:it.mathworks.com,2005:Question/6011772020-09-28T10:13:28Z2020-09-30T06:03:47ZHow to use sostools to find S matrix in AREThis is the parameter
clear; close; clc;
syms a1_head a2_head b hstar
%Parameter Massa
m1 = 8095; % massa train set 1 dalam kg
m2 = 8500; % massa train set 2 dalam kg
g = 10;
c_0_1 = 0.01176;
c_1_1 = 0.00077616;
c_2_1 = 4.48 ;
c_0_2 = 0.01176 ;
c_1_2 = 0.00077616;
c_2_2 = 4.48;
v_0 = 300;
hstar = 120;
a_1 = -1./m1.*(c_1_1 + 2.*c_2_1.*v_0);
a_2 = -1./m2.*(c_1_2 + 2.*c_2_2.*v_0);
a_1_head = 1-(a_1.*hstar);
a_2_head = 1-(a_2.*hstar);
b = 1;
This is the model
% Model data
A = sym(zeros(4,4));
A(1,2) = a_1_head;
A(3,2) = (a_2_head) - 1; A(3,4) = a_2_head;
display(A);
B = sym(zeros(4,2));
B(1,1) = -b*hstar;
B(2,1) = b;
B(3,2) = -b*hstar ;
B(4,1) = -b; B(4,2) = b;
display(B);
This is the Q and R matrix for LQR
% Q and R matrices for ARE
Q = [10 0 0 0;
0 10 0 0;
0 0 10 0;
0 0 0 10;
];
R = sym(zeros(2,2)); R(1,:) = [1 0]; R(2,:) = [0 1]; display(R);
This is the S matrix that I want to find the value
% Matrix S to find
svar = sym('s',[1 16]);
S = [svar(1:4); svar(5:8); svar(9:12); svar(13:16)];
S(2,1) = svar(2);
S(3,1) = svar(3);
S(3,2) = svar(7);
S(4,1) = svar(4);
S(4,2) = svar(8);
S(4,3) = svar(12);
display(S);
This is the Algebra Ricatti Equation (ARE) in LQR Control
% LHS of ARE: A'*S + S*A' - S*B*Rinv*B'*S
left_ARE = transpose(A)*S + S*A - S*B*inv(R)*transpose(B)*S;
display(left_ARE);
% RHS of ARE: -Q
right_ARE = -Q;
display(right_ARE);
I want to use sostools and sedumi to find S semidifinite matrix
syms s1 s2 s3 s4 s6 s7 s8 s11 s12 s16
[Sol_s] = sosgetsol(left_ARE,right_ARE,sedumi)
disp(Sol_s)
But why there is error like this
Error using sedumi (line 232)
Should have at least (A,b) or (A,c) arguments
Error in Algebraricattieqvpa (line 75)
[Sol_s] = sosgetsol(left_ARE == right_ARE,sedumi)
my left_ARE is A*x
my right_ARE is B
but why can't get the answer?Ivan Dwi Putrahttps://it.mathworks.com/matlabcentral/profile/authors/13105564tag:it.mathworks.com,2005:Question/4985172019-12-31T01:19:52Z2020-09-30T06:03:46ZHow to make threshold lines and mark the 1st intersection line?Hi, I would like to ask a few questions:
How to set 20% upper and lower threshold from the signal maximum amplitude and make a line of the thresholds.
From the upper threshold line, how to find and mark the 1st line intersection between upper threshold and signal.
How to expand the signal that only focus on the line intersection automatically.
I really appreciate if anyone can help me with matlab coding.
load energy_bigcircle_placement1 %load file
[p,s,mu]=polyfit((1:numel(bigcircle_ant2))',bigcircle_ant2,20);
f_y=polyval(p,(1:numel(bigcircle_ant2))',[],mu);
bigcircle_ant2_data=bigcircle_ant2 - f_y;
tms=(0:numel(bigcircle_ant2_data)-1)/Fs;
figure (1)
plot(tms,bigcircle_ant2_data)
axis tight
title('Signal and Scalogram')
xlabel('Time(s)')
ylabel('Amplitude')
grid on
Regards.melaty amirruddinhttps://it.mathworks.com/matlabcentral/profile/authors/17154135tag:it.mathworks.com,2005:Question/6023172020-09-30T06:02:43Z2020-09-30T06:02:43Zhow to make a mathlab code with different values of k or without the value of k which is the same as k is a random number of phi and phi = (1,2, ...., m * n)I have
m = 4 and n = 5
set phi = (1,2,3, ..., m * n)
k = rand (phi)
I want to make a loop with the accuracy of each step there cannot be the same k value or every k that appears in the first step the value must come out of phi. the loop until phi is empty .. please solve it?
clc;clear;close all;
c=[10 2 20 11
12 7 9 20
4 14 16 18];
s=[8
7
9
3
5
];
d=[6 8 10 4 4];
[m,n]=size(c);
%s1=zeros(m,1);
%d1=zeros(1,n)
x=zeros(m,n);
phi=1:m*n
for i=1:m*n
k= randi(length(phi))
i=round(1+(k-1)/n);
j=[1+mod((k-1),n)];
x(i,j)=min(s(i),d(j))
s(i)= s(i)-x(i,j)
d(j)= d(j)-x(i,j)
if phi==k
continue
end
end Muhammad Sam'anhttps://it.mathworks.com/matlabcentral/profile/authors/7844581tag:it.mathworks.com,2005:Question/6018792020-09-29T11:10:41Z2020-09-30T05:57:52Zaveraging and interpolating random number of rows of dataHello, I have a list 800 particles data in an excel file. A total of 174755 rows...
Is there a way to extract these values and then average them based on their time point, later interpolate them based on the time point. I would like to average the first row of every particle 1,2,3....800. So after NaN, it will consider that as row 1,2,3...last number before NaN, then another row 1 again.
For example:
1 5
2 6
3 7
NaN
NaN
NaN
4 8
5 9
6 10
10 11
NaN
NaN
NaN
7 1
8 2
9 3
So the output average should be:
4 4.67
5 5.75
6 6.67
10 11
filename = 'plottemperature.xlsx';
T = xlsread(filename); %read excel file
[rows,columns] = size(T); %List the number of rows and columns
nanLocations = isnan(T); %declare all NaN locations in the excel file
for row = 1: rows
for col = 1:columns
if ~nanLocations(row,col) %I wanted to write it so that after the 3rd NaN it will be another row 1
%I am not sure how to continue from here to set the rows after every NaN as row 1 and then average all row 1
Please guide me. Thank you very much! Bryan Tanhttps://it.mathworks.com/matlabcentral/profile/authors/15037189tag:it.mathworks.com,2005:Question/6023052020-09-30T04:42:21Z2020-09-30T05:47:42ZExpected FFT bin widths from signal is double what I think it should beI am sampling a signal taken from an oscilloscope an I’m trying to make the frequency bin widths from my FFT be what I believe they should be.
Ex: I capture 20 complete waveform periods over 0.4s, at 50Hz, with 800,000 samples (I need to max out my oscilloscope for high accuracy measurements. My step size between samples is 5.0E-7. Therefore I believe my bin width from a standard FFT should be:
1/(capture period) = 1/0.4 = 2.5Hz
However the actual bin widths I see on me frequency spectrum is 5Hz (47.5Hz > 52.5Hz around 50Hz).
I is very important that my bin widths are correct because this is what I am measuring to determine the resolution of measurement.
From this I plan to apply some cross correlation and pseudospectrum functions to try maintain a high resolution (small bin width) using fewer captured waveform period.
F_data = wf_YData(:,fftcount);
X_step = (wf_XData(:,2))-(wf_XData(:,1));
Ts = X_step;
N = size(F_data,1);
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
FF = fft(F_data);
P2 = abs(FF/N); %P2 = two sided spectrum
P1 = P2(1:N/2+1); %P1 = single sided spectrum
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(N/2))/N;
dB_P1 = 20*log10(P1);
figure(2)
plot(f,P1);
grid;
xlim([0 2000]);
Thus, can anyone see the issue in my code that is causing my bin widths to be double what they should? Everything else is being displayed and plotted correctly and match what I get on the oscilloscope. I’m using single side band FFT.
I just recently started looking into bin widths, so am I just overlooking something basic.
My current plots:
Michael Anderssonhttps://it.mathworks.com/matlabcentral/profile/authors/17930546tag:it.mathworks.com,2005:Question/6021432020-09-29T20:06:19Z2020-09-30T05:43:36ZI am facing a problem in saving values from table to .mat file in app designer. I have to trees with two-two nodes, and one table is linked to the tree. When I select the nodes first, it should show the values taken from a .mat file, in the table. I want to change some values of the nodes and save them in the same .mat file. It is saving different values to the nodes automatically, and sometimes I am getting an error "Dot indexing is not supported for variables of this type''. Below find the code of the app designer.
properties (Access = private)
tab
Dx
Dy
Dz
IXX
IYY
IZZ
end
% Callbacks that handle component events
methods (Access = private)
% Selection changed function: Tree
function TreeSelectionChanged(app, event)
selectedNodes = app.Tree.SelectedNodes;
app.tab = load('property.mat');
if strcmp(selectedNodes.Text,'Center of Mass')
app.UITable.Data(1,1) = app.tab.dx(1);
app.UITable.Data(2,1) = app.tab.dy(1);
app.UITable.Data(3,1) = app.tab.dz(1);
end
if strcmp(selectedNodes.Text,'Inertia')
app.UITable.Data(1,1) = app.tab.Ixx(1);
app.UITable.Data(2,1) = app.tab.Iyy(1);
app.UITable.Data(3,1) = app.tab.Izz(1);
end
end
% Selection changed function: Tree_2
function Tree_2SelectionChanged(app, event)
selectedNodes2 = app.Tree_2.SelectedNodes;
app.tab = load('property.mat');
if strcmp(selectedNodes2.Text,'Center of Mass2')
app.UITable.Data(1,1) = app.tab.dx(2);
app.UITable.Data(2,1) = app.tab.dy(2);
app.UITable.Data(3,1) = app.tab.dz(2);
end
if strcmp(selectedNodes2.Text,'Inertia2')
app.UITable.Data(1,1) = app.tab.Ixx(2);
app.UITable.Data(2,1) = app.tab.Iyy(2);
app.UITable.Data(3,1) = app.tab.Izz(2);
end
end
% Cell edit callback: UITable
function UITableCellEdit(app, event)
selectedNodes = app.Tree.SelectedNodes;
app.tab = load('property.mat');
if strcmp(selectedNodes.Text,'Center of Mass')
app.Dx = app.UITable.Data(1,1);
app.Dy = app.UITable.Data(2,1);
app.Dz = app.UITable.Data(3,1);
x1 = app.Dx;
y1 = app.Dy;
z1 = app.Dz;
dx = [x1,app.tab.dx(2)];
dy = [y1,app.tab.dx(2)];
dz = [z1,app.tab.dx(2)];
Ixx = app.tab.Ixx;
Iyy = app.tab.Iyy;
Izz = app.tab.Izz;
save('property.mat','dx','dy','dz','Ixx','Iyy','Izz');
end
if strcmp(selectedNodes.Text,'Inertia')
app.IXX = app.UITable.Data(1,1);
app.IYY = app.UITable.Data(2,1);
app.IZZ = app.UITable.Data(3,1);
dx = app.tab.dx;
dy = app.tab.dy;
dz = app.tab.dz;
Ixx1 = app.IXX;
Iyy1 = app.IYY;
Izz1 = app.IZZ;
Ixx = [Ixx1,app.tab.Ixx(2)];
Iyy = [Iyy1,app.tab.Iyy(2)];
Izz = [Izz1,app.tab.Izz(2)];
save('property.mat','dx','dy','dz','Ixx','Iyy','Izz');
end
selectedNodes2 = app.Tree_2.SelectedNodes;
app.tab = load('property.mat');
if strcmp(selectedNodes2.Text,'Center of Mass2')
app.Dx = app.UITable.Data(1,1);
app.Dy = app.UITable.Data(2,1);
app.Dz = app.UITable.Data(3,1);
x2 = app.Dx;
y2 = app.Dy;
z2 = app.Dz;
dx = [app.tab.dx(1),x2];
dy = [app.tab.dx(1),y2];
dz = [app.tab.dx(1),z2];
Ixx = app.tab.Ixx;
Iyy = app.tab.Iyy;
Izz = app.tab.Izz;
save('property.mat','dx','dy','dz','Ixx','Iyy','Izz');
end
if strcmp(selectedNodes2.Text,'Inertia2')
app.IXX = app.UITable.Data(1,1);
app.IYY = app.UITable.Data(2,1);
app.IZZ = app.UITable.Data(3,1);
dx = app.tab.dx;
dy = app.tab.dy;
dz = app.tab.dz;
Ixx2 = app.IXX;
Iyy2 = app.IYY;
Izz2 = app.IZZ;
Ixx = [app.tab.Ixx(1),Ixx2];
Iyy = [app.tab.Iyy(1),Iyy2];
Izz = [app.tab.Izz(1),Izz2];
save('property.mat','dx','dy','dz','Ixx','Iyy','Izz');
end
end
end
Saurabh Chaudharyhttps://it.mathworks.com/matlabcentral/profile/authors/11546495tag:it.mathworks.com,2005:Question/6015252020-09-28T20:00:31Z2020-09-30T05:38:04ZTimed out on waiting for AXI write response.After successfully running the HDLWA via the JTAG route, i create an AXI master object in MATLAB and then i try and write to memory to a specific register but i get an error as follow:
h.writememory(hex2dec('A4000100'), 6)
Error using fpgadebug_mex
Timed out on waiting for AXI write response. The aresetn signal on the MATLAB AXI Master IP is stuck at active low.
Error in hdlverifier.AXIMasterJTAG/writememory
I am not sure if it's my setup in Vivado that's incorrect but would appreacite any guidance/help on this error. Praneet Kalahttps://it.mathworks.com/matlabcentral/profile/authors/8262831tag:it.mathworks.com,2005:Question/5932182020-09-14T07:08:28Z2020-09-30T05:30:48ZMATLAB online is lagging a lot on my device inspite of excellent specificationswhile learning simulink onramp, the software is stuck in section 7.2, task 1. Also it has been lagging a lot previously, while the other softwares on my device is working just fine, only matlab online is lagging. Shubham Murarihttps://it.mathworks.com/matlabcentral/profile/authors/19047861tag:it.mathworks.com,2005:Question/5996112020-09-25T07:05:03Z2020-09-30T05:30:31ZPoint registration - How to get the eigenvectors to have a consistent direction?Hello,
I'm trying to replicate the algorithm of the attached paper. It's about feature-based correspondence based on the eigenvectors. I'll summarize:
We have a point cloud/shape (as in Figure 2, which I'm trying to replicate) and create a matrix H (adjacency of the points) which describes the relation of the intradistances (not interdistances) in an image. From this matrix we calculate the eigenvectors and values. They have to be reordered from big to small and the sign of the vector adapted, so that they have a consistent direction. The rows describe the features. Finally we calculate square of the euclidean distance between the features to get the matrix Z. The smallest number in every row tells us, which point corresponds to which.
Now I get the same numbers for the eigenvectors, but not always the right sign. For the matrix U1 of the eigenvectors of the first body, the second column should be multiplied by -1. For the matrix U2 of the eigenvectors of the second body, the second and fourth column should be multiplied by -1.
I tried to find out if this is somehow apparent when calculating the angles between eigenvectors (see the code) but the result (see the matrix bellow the code) doesn't tell me anything. Maybe you have a better eye.
for i = 1:minNofP;
for j = 1:minNofP;
ThetaInDegrees.CosTheta(i,j) = max(min(dot(U1(:,i),U2(:,j))/(norm(U1(:,i))*norm(U2(:,j))),1),-1)
ThetaInDegrees.Angle(i,j) = real(acosd(ThetaInDegrees.CosTheta(i,j)));
end
end
The problem is, that without the adaptation of the sign, the algorithm doesn't work. This may be a "just" a mathematics problem, but I am not able to solve it and I know that here there are a lot of people a lot more knowlegdeable (and smarter) than me.
There are many things attached:
1) The pdf of the article, in case you want to thow an eye on it. The consistent direction thing is explained on the third page on the right side before the ecuation.
2) Adjacency_V2 is an adapted version of the adjacency function from https://www.mathworks.com/matlabcentral/fileexchange/29227-eigen-function-of-the-laplacian. I adapted it to use my euclidean distance function. It should not be a problem, it has worked fine for me.
3) TruncateToMinNumber is a function to truncate a matrix to the smaller number of eigenvectors. It doesn't have an effect on this example, as the matrices have the same amount of eigenvectors and so they stay the same.
4) Correct EV have the correct eigenvectors given on the paper. The algorithm works with it. I've used it to compare.
5) DistanceBetweenF is my function for the euclidean distance between the features.
6) Features_EV_EW_v2 is my code. I've written %IGNORE on the lines you don't need but I dind't want to erase.
I tried to make the question as complete as possible but so summarized that someone actually reads it. I'm very sorry if I forgot some function or something relevant for you to be able to help me. I will edit it in as soon as I know about it.
As always thank you very much.Diego Henshttps://it.mathworks.com/matlabcentral/profile/authors/6473449tag:it.mathworks.com,2005:Question/5659672020-07-16T11:18:46Z2020-09-30T05:28:06ZMobile robot path planning- Valid or feasible path
Am trying to build a genetic algorithm to find the shortest path. findpath() use A* which is build in.
My question is: Is there a function or method to examine new generated path that is valid or not?
Hamza Turabiehhttps://it.mathworks.com/matlabcentral/profile/authors/5059247tag:it.mathworks.com,2005:Question/6016902020-09-29T03:42:10Z2020-09-30T05:23:16Zsolution of 3d nonlinear equationx_p, y_p, z_p=(4, 5, 2)
x_1, y_1, z_1=(8, 9, 5)
x_2, y_2, z_2=(2, 5, 1)
x_3, y_3, z_3=(6, 1, 3)
t_1=5.692820*10^-9
t_2=-2.924173*10^-9
t_3=-12.010097*10^-9
c=3.0*10^8
and my three equations are
eqn1 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_1)^2+(y(s)-y_1)^2+(z(s)-z_2)^2)-(c*t_1)
eqn2 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_2)^2+(y(s)-y_2)^2+(z(s)-z_2)^2)-(c*t_1)
eqn3 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_3)^2+(y(s)-y_3)^2+(z(s)-z_3)^2)-(c*t_1)
where only x(s), y(s), z(s) are unknown are rest all are known
BEST REGARDSali hassanhttps://it.mathworks.com/matlabcentral/profile/authors/17127843tag:it.mathworks.com,2005:Question/6023082020-09-30T04:55:52Z2020-09-30T05:31:47ZGetting linear results from ODE45 instead of exponentialI aam very new to Matlab and have this project to figure out the velocity vs time and displacement vs time of a sphere falling from rest. With my code I am able to get the displacement to work which is r(1) but my velocity vs time plot is linear when it should be exponential. I've tried retyping the whole equation for the code and inputting the squared term in all the ways I could figure out with no success.
function Projecto
clear all
tr=[0 15]; %seconds
initv=[0 0]; %starting point
[t,y]=ode45(@sphere, tr, initv);
plot(t,y(:,1))
ylabel('x (m)')
xlabel('time(s)')
figure
plot(t,y(:,2))
ylabel('velocity (m/s)')
xlabel('time(s)')
function r=sphere(t,y)
mass=167.6;
g=9.81;
rho=1.21; %kilogram per meter cubed
d=.01; %meters
r=zeros(2,1);
r(1)=y(2);
r(2)=(mass*g-rho*g*(pi/6)*d^3-0.5*rho*y(2)*abs(y(2))*(pi/4)*d^2*0.5)/(mass+(pi/12)*d^3*rhoConnor Jackhttps://it.mathworks.com/matlabcentral/profile/authors/17782676tag:it.mathworks.com,2005:Question/5674082020-07-19T11:00:03Z2020-09-30T05:12:47Zc++ code generation how can I generate a c++ code feom matlab code?
hi i actually want to generte a c++ code from a matlab code to controle a mobile robot for autonom navigation so I used the navigation toolbox and now I want to convert this code into a c++ code so that i can implement it in my arduino eline smithhttps://it.mathworks.com/matlabcentral/profile/authors/19016122tag:it.mathworks.com,2005:Question/6023112020-09-30T05:11:14Z2020-09-30T05:11:14ZAre there any functions/blocks to print the spectrum of spectrum Analyser to file or just output its data to file automatically in simulinkI do find there is a manual way that FIle->Print to Figure or Print Preview. But I got hundreds of cases to do, and up to 8 spectrums in one case. If I do them manually, my life will become miserable. I am wondering if there are some functions or blocks that can do it automatically.
Many ThanksGeng Shaohttps://it.mathworks.com/matlabcentral/profile/authors/16348229tag:it.mathworks.com,2005:Question/6020382020-09-29T16:01:34Z2020-09-30T05:10:14Zwhenever i use individual value of time (Tv) the output function (F) giving right value but using time in the form of loop ,output function gives wrong result for all.How to fix this ?clc
clear all
c1 = 3.742*10.^8;
c2 = 1.43878*10.^4;
sigma = 5.67*10.^-8;
lamda_1 = 8;
lamda_2 = 13;
Tv = -10:5:30;
F = zeros(size(Tv));
count = 1;
for T=Tv
fun = @(lambda) c1./(lambda.^5.*(exp(c2./(lambda * T+273)))-1);
F(count) = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4)
plot(T, F(count), '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
grid
count = count + 1;
end
xlabel('Temperature')
ylabel('Fraction in atmospheric window)')
title('Fraction of the radiation emitted in the atmospheric window as a function of temperature')
legend('T=-10','T=-5','T=0','T=5','T=10','T=15','T=20','T=25','T=30')
hold offSarvjeet Singhhttps://it.mathworks.com/matlabcentral/profile/authors/13298611tag:it.mathworks.com,2005:Question/6018882020-09-29T11:29:26Z2020-09-30T05:04:38Zput image on a framefunction [P] = matri(n) %
c_dim = [2 2]; %
P = ones(c_dim); %
for i = 1:n-1
P = padarray(P,[1,1]) + 1;
end
end
>> p1 = matri(6);
>> imshow(p1); %this shows the frame
i need to create a function that puts an image (not specified what image) to a frame like this. The photo should be placed on the white part
any help will be welcomed :)Hano Jakhttps://it.mathworks.com/matlabcentral/profile/authors/19740275tag:it.mathworks.com,2005:Question/6019122020-09-29T11:57:33Z2020-09-30T05:03:07ZSymsum every other stepHi everybody,
I'm trying to get a symsum runnin' with a count of every other step.
The Formula itself looks like this:
My current code
a=2:2:10
syms p [1 size_x_r_sampling_meter];
f=k^2*p
f1=symsum(f,k,a)
obvjously doesn't work...
Could you please give me a hint, how to solve this problem?
Very best
Christian Christian S.https://it.mathworks.com/matlabcentral/profile/authors/13123336tag:it.mathworks.com,2005:Question/6019002020-09-29T11:48:23Z2020-09-30T05:01:42Zconnrect two blocks in simulation How i can connect these two block
Ahmad Badranhttps://it.mathworks.com/matlabcentral/profile/authors/13856489tag:it.mathworks.com,2005:Question/6019152020-09-29T12:00:08Z2020-09-30T04:57:08ZExport Structure to csv fileHi everyone,
I'm trying to export my data which is saved in a structure to a csv file. The structure is two dimensional but contains vectors in some cells. So far I tried to convert it in a table and save it using writetable, but the vectors were not recorded correctly.
Thanks for any advice,
Kathrin Kathrin Sadushttps://it.mathworks.com/matlabcentral/profile/authors/17260061tag:it.mathworks.com,2005:Question/5998842020-09-25T14:35:18Z2020-09-30T04:54:56ZHow to replace two columns in a txt file?Dear All,
I have a txt file which contains strings and numerical columns. Here are some samples of this txt file:
3 'CHSTRSVC' 345.00 2 0.00 0.00 1 1 1.0269 -11.382 1
4 'ORRINGTN' 345.00 1 0.00 0.00 1 1 1.0191 -16.365 1
3146 'ORRINGTN' 345.00 1 0.00 0.00 1 1 1.0162 -13.797 1
3147 'ORRINGTN' 345.00 1 0.00 0.00 1 1 1.0179 -13.586 1
......
I want to replace the values in the last 2 columns with updated values, and save the updated values in the same txt file. So the txt file has only two columns updated. For example, in the first row, I want to replace 1.0269 with 0.9987 and -11.382 with -10.5634.
Is there a simple way to do it?
Thanks.
BensonBenson Gouhttps://it.mathworks.com/matlabcentral/profile/authors/4652929tag:it.mathworks.com,2005:Question/5993982020-09-24T20:11:03Z2020-09-30T04:49:03ZProblems with comm.RayTracingChannelWhen I try to use
rays = raytrace(tx,rx,rtpm);
rtchan = comm.RayTracingChannel(rays{1},tx,rx);
I receive the error Unable to resolve the name comm.RayTracingChannel. Why?Gabriel Clementehttps://it.mathworks.com/matlabcentral/profile/authors/8470546tag:it.mathworks.com,2005:Question/6019092020-09-29T11:51:23Z2020-09-30T04:42:46ZMy matlab grader account was accidentally tied to my classmate’s account. How can I unbindwhen I applied to enter one course on matlab grader, my matlab grader account was accidentally tied to my classmate’s account. How can I unbind张 张https://it.mathworks.com/matlabcentral/profile/authors/19749176tag:it.mathworks.com,2005:Question/6022992020-09-30T04:34:13Z2020-09-30T04:41:07ZHow could I convert my png images to tiff?this is my code:
clc; clear; close all;
imagePath = 'C:\Users\images';
savePath = 'C:\Users\images_tiff';
fileNames = dir(imagePath);
fileNames = fileNames(3:end);
for i = 1:size(fileNames,1)
varH =fileNames(i).name;
I= imread([imagePath '\' varH]);
imwrite(I ,[savePath '\' varH,'.tiff'],'tiff')
end
it convert my images ti tiff but add .png extension to themLeila Sharbafhttps://it.mathworks.com/matlabcentral/profile/authors/19031246tag:it.mathworks.com,2005:Question/6019452020-09-29T12:46:47Z2020-09-30T04:35:50ZRotation of 4 veticesHello,
Hope you are fine,
I have 4 vertices that form a square,
each vertices v is of coordinate x y z
v1= [x1 y1 z1]
v2= [x2 y2 z2]
v3= [x3 y3 z3]
v4= [x4 y4 z4]
I want to rotate this square toward identified vector of direction n=[a b c]
thanks for your help
Best regards
SaeedSaeed Zahranhttps://it.mathworks.com/matlabcentral/profile/authors/6415958tag:it.mathworks.com,2005:Question/4296722018-11-13T19:36:48Z2020-09-30T04:35:46ZLaTeX interpreter but sans-serif font on figuresHi,
On LaTeX I often use the
\usepackage{cmbright}
font when I want to have a clean, sans-serif font both in the text and in the mathematical formula I write.
In order to have an homogeneous result between my figures and the text, I would like the text in my figures (labels, axis ticks, title, annotations...) to be as well in this font.
Unfortunately so far on Matlab, when using the LaTeX interpreter, only the default font is available. I would like to be able to write both text and mathematical formulas in a sans-serif font (and the same for both text and math) on the figures I plot.
Is it possible?
I am on Mac OS 10.14.1 (Matlab 2018a) and also on Ubuntu 18.10 (Matlab 2018b).
Thank you for your help!
LeChathttps://it.mathworks.com/matlabcentral/profile/authors/4392341tag:it.mathworks.com,2005:Question/6022932020-09-30T04:12:54Z2020-09-30T04:32:15ZMeaning of hypergeometric function as an answer to an indefinite integral.syms a x real
expression= sqrt(1+a^2/x^4);
F = int(expression,x);
This yields F to be a "hypergeometric function". Does that mean that a closed form indefinite integral does not exist for 'expression'?Prajwal Gowdru Shanthamurthyhttps://it.mathworks.com/matlabcentral/profile/authors/19675561tag:it.mathworks.com,2005:Question/6022962020-09-30T04:30:38Z2020-09-30T04:30:38ZInfeasible solution with bigger systems: what can be the cause ?hello all,
I have problem using gamultiobj (infeasibility).. I have decided to simplify things trying to find where the problem is. So, I used gamuliobj with one objective and a small test system, I got feasible results, although the rsults are not as good as those found by solvers like multistart or patternsearch , but it returned a feasible solution (is it logical that patternsearch and multistart give better solution than gamultiobj ), by the way, my problem is NLP.Now I have trouble getting a feasible solution with a bigger test systems... I didnot provide initial population and didnot set special settings for gamuliobj....
I just used it like that
opts_ga = optimoptions('gamultiobj','Display','off');
tic,[x,f,exitf,output,population,score] = gamultiobj(obj,14,A,B,Aeq,Beq,LB,UB,NLC,opts_ga);toc
So What could be the problem, could it be something related to the settings of gamuliobj or is my choice of this solver not right. Can you help, pls.
Thanks
Best,mayar madbolyhttps://it.mathworks.com/matlabcentral/profile/authors/19091554tag:it.mathworks.com,2005:Question/6018372020-09-29T09:41:29Z2020-09-30T04:26:47ZSolve system of differential equations using Euler forward and ode45I have a basic SIR model which is described by three differential equations:
and I want to solve these using Euler forward and ode45. I have never worked with these types of problems before but from research I have found that for Euler forward I should use the equations:
But all the examples I have seen using this are given initial values for the different parameters, which I haven't. So I don't even know where to start. I would appreciate if someone could push me in the right direction of how to solve this. Thank you!Katara Sohttps://it.mathworks.com/matlabcentral/profile/authors/19609646tag:it.mathworks.com,2005:Question/6022722020-09-30T02:45:59Z2020-09-30T04:24:33ZWriting Functions that take inputs?Need help getting this function to execute.
So far I have:
r = input('What is the radius of the circle?')
x = input('What is the X - coordinate for the center of the circle?')
y = input('What is the Y - coordinate for the center of the circle?')
c = 'k';
function circleplot(x,y,r,c)
hold on
th = 0:pi/50:2*pi;
x_circle = r * cos(th) + x;
y_circle = r * sin(th) + y;
plot(x_circle, y_circle);
fill(x_circle, y_circle, c)
plot(x, y, 'kp', 'MarkerSize',15, 'MarkerFaceColor','k')
axis equal
end
When I run the code nothing happens expect the prompts asking me for data. Any advice?Tyler Bodnarikhttps://it.mathworks.com/matlabcentral/profile/authors/19286438tag:it.mathworks.com,2005:Question/6020292020-09-29T15:51:22Z2020-09-30T04:24:04ZTrying to make a 6x6 checkerboard matrix using for loops and no if statements. trying to get my code down to 7 lines instead of 8.Trying to get the bolded code consolodated into 7 lines instead of 8 in order to make a 6x6 checkerboard matrix. I feel like somehow i can nest together all three for loops and only have one line for A()=a
n=6;
a=1;
A=zeros(n,n);
for i=1:2:n-1 %rows 1,3,5
for j=1:2:n %columns 1,3,5
A(i,j)=a;
end
for k=2:2:n %columns 2,4,6
A(i+1,k)=a;
end
end
display(A)Mary Jean Savitskyhttps://it.mathworks.com/matlabcentral/profile/authors/17758736