Quantcast
Channel: MATLAB programming & numeric computing platform
Viewing all 31104 articles
Browse latest View live

Apply colormap and caxis directly to image matrix

$
0
0

Hello,

I have and image and a colormap, that I usually apply like this:

my_colormap = ....;
my_image = imread(....);
figure(1);
imshow(my_image);
colormap(my_colormap);
caxis([minVal maxVal]);

What I'd like to do is, instead of applying the colormap and the caxis to the figure, I'd like to apply it directly to the image matrix (my_image) for further processing.

At the moment, this is what I tried:

(IMPORTANT: my_image is actually a matrix with double values, also negative values. I figured that when I do imshow, it gets converted to 8 bits or 16 bits uint. I verified this by using im2uint16 to my image and then using imwrite and opening that image with an image viewer. It indeed look the same as the one in the figure).

my_colormap = ....;
% this is a 64 bits values with sign
my_image = imread(....);
% This works and the image looks the same as just doing imshow(my_image)
my_image = im2uint16(my_image);
% This does not work, when I show my_image it looks different than just applying colormap(my_colormap) to a figure
my_image = ind2rgb(my_image, SigColourMap);
% ?? caxis: I still do not know what to do to the matrix to apply the caxis

submitted by /u/giamboscaro
[link] [comments]

Matlab and logical masks

$
0
0

Hi. I’m taking Matlab as a course online over the summer and I’ve hit a huge bump in the road. I can’t even begin to understand vectorization, logical masks or applying them. Maybe its because its 3am and I’m stressing out that my assignments due in 9 hours but I have to be at work in 5 hours. But my professor posted these three short videos explaining the topic, and his videos are usually pretty helpful but this time, I am just so lost. I don’t understand anything. Can anyone direct me to a youtube video or something of the sort? I’ve tried looking up “Logical masks Matlab” and nothing comes up at all except videos that aren’t in english. I’d honestly be crying if I had the time for it.

Thanks for your help

submitted by /u/SonOfGoose66
[link] [comments]

An annoying error

$
0
0

I’m getting the following error -

Derivative of state '1' in block 'Plant model/Varying Lowpass Filter/FOS/Integrator' at time 0.4 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)

Can someone please help me solve this, I have been trying for hours but haven’t gotten any success. After spending days to build the model, I end up with this error (the frustration is real lol).

Thanks

submitted by /u/Francescodepazzi
[link] [comments]

Why do I keep getting negative motor speed?

Using the Curve Fitting Toolbox for Heat Conduction

$
0
0

I'm trying to use the following equation for a bar being heated at one end, where the temperature through time is being measured by thermocouples placed along the length of the bar:

(T(x,t) - T_i)/(T_o - T_i) = 1 - erf(x/sqrt(4*a*t)), or

T(x,t) = T_i + (T_o - T_i)*(1 - erf(x/sqrt(4*a*t)))

where a is the parameter I'm trying to fit with; I have x, t, T_o, T_i, and T(x,t).

When I plot the data, everything looks like it should for a standard heat conduction problem, but when I go into the curve fitting toolbox and try to use the equation above for a custom fit, I keep getting values of a with a negative R2 value, even though the data looks good.

I was wondering what might be causing this issue and how I can fix it. Thanks!

submitted by /u/Neo_Unidan
[link] [comments]

How do i resolve this error ?

$
0
0

test1 Error using test1 (line 1) Expected libraries to match one of these values:

'Adafruit/BNO055', 'Adafruit/MotorShieldV2', 'CAN', 'I2C', 'MKRMotorCarrier', 'RotaryEncoder', 'SPI', 'Serial', 'Servo', 'ShiftRegister', 'Ultrasonic'

The input, 'ExampleLCD/LCDAddon', did not match any of the valid values.

This is the program

%Program Name is Smart_car_Parking.m: %this program display the available parking slot and allow user to enter in %parking lot by pressing button. %Created on November,17,2019 by A.Patel,H.Patel and H.Parikh %It runs on the Arduino Uno Board with 'COM3' Port %it uses the 'Servo' and 'LCDAddon' Libraries from MATLAB %Input Variable %Entry Button, Exit Button and slot %Output Variable %Servo, RGB LED and LCD Screen %Entry button is assigned D8 pin and Exit button is assigned to D11 pin. %Servo is assigned to D9 pin %LCD Screen is assigned D7,D6,D5,D4,D3 and D2 Pins. %RGB LED is assigned to two pins, D12 for RED Light and D13 for Green Light clear; %This will clear all the variable from the workspace a = arduino('com3','UNO','Libraries',{'ExampleLCD/LCDAddon','Servo'}); s=servo(a,'D9'); %D9 pin is assign for servo Output slot=13; %Maximum Capacity of Parking lot lcd = addon(a,'ExampleLCD/LCDAddon','RegisterSelectPin','D7','EnablePin','D6','Da taPins',{'D5','D4','D3','D2'}); initializeLCD(lcd,'Rows',2,'Columns',16); printLCD(lcd,'!!Welcome!!'); %this will print '!!Welcome!!' message printLCD(lcd,'Availableslot:13');%this will print 'Avaliableslot:13'message configurePin(a,'D8','DigitalInput'); configurePin(a,'D11','DigitalInput') configurePin(a,'D12','DigitalOutput'); configurePin(a,'D13','DigitalOutput'); while 1 %This loop is given to continuously run the Program writeDigitalPin(a,'D12',1) % D12 pin will turn the light to RED writeDigitalPin(a,'D13',0) % D13 pin will remain close entrybutton=readDigitalPin(a,'D8');%Read Value of D8 pin (Entry Button) exitbutton=readDigitalPin(a,'D11');%Read Value of D11 pin (Exit Button) if entrybutton==1 && slot>0 writeDigitalPin(a,'D12',0) %Red Light turn off writeDigitalPin(a,'D13',1) %Green Light turn on writePosition(s,0.5) %Servo will operate and rotate to position 0.5 pause(4) %Wait for Car to Pass writePosition(s,0) %Servo will come backs to position 0 slot=slot-1; %Available slot will reduce by one if slot>0 printLCD(lcd,'!!Welcome!!'); printLCD(lcd,char("Availableslot:"+slot+'')); elseif slot==0 printLCD(lcd,'!Plz Come Back!'); printLCD(lcd,char("Availableslot:"+slot+'')); end elseif exitbutton==1 && slot<13 writeDigitalPin(a,'D12',0) %Red Light turn off writeDigitalPin(a,'D13',1) %Green Light turn on writePosition(s,0.5) %Servo will operate and rotate to position 0.5 pause(3) %Wait for Car to Pass writePosition(s,0) %Servo will come backs to position 0 slot=slot+1; %Available slot will increase by one if slot>0 printLCD(lcd,'!!Welcome!!'); printLCD(lcd,char("Availableslot:"+slot+''));

submitted by /u/Levyloveshismoney
[link] [comments]

Abstract class or not?

$
0
0

Is it worth using an abstract class for this? I have 5 classes of numerical optimisation algorithms that share a few properties and methods. I made the abstract class as a template, here's the class

classdef (Abstract) Solver < handle % Abstract class for optimisation algorithms properties position % Position in parameter space cost_function % Function handle to objective function cost % Current cost dimensions % Number of dimensions evaluations = 0 % Evaluations counter end methods pos = step(self) % Step solver settings(self) % Set solver parameters reset(self) % Reset/Reinitialise solver end end 

My main issue is that if someone wants to only use one of my classes, they will also need the abstract class, which (I assume) may be annoying for the user.

submitted by /u/saysokmate
[link] [comments]

Using dsolve

$
0
0

So I've solved a first oder differential equation using dsolve with a single initial condition. The output I got is correct, however I now need to evaluate this dsolve expression. The output of the dsolve looks like this:

exp(-(Ar*H*t)/(C*m))*(Ta - TO) - Ta

Where Ar,H,m,C,Ta, AND TO were all predefined variables with a numerical value. 't' will come from a single value from a matrix, and I need to evaluate the entire equation at that point 't'. How can I do this? I've tried using subs(....) to no avail.

submitted by /u/Bobby_Shmurda6969
[link] [comments]

Silver taking waaayyy too long

$
0
0

Hello,

It’s my first time using a solver ( it’s for my undergraduate research) and it’s taking excessive time like it’s been 9 hours and the solver has reached around 20secs (the total is 400 secs). I did google it to find some solutions. But there are various ways to minimize the solver time. Is there a method that works 100%? Cuz I don’t have the time to try all the methods listed on the internet. So if anyone can just tell me a method that reduces the solver time , it would be great.

Thanks

submitted by /u/Francescodepazzi
[link] [comments]

Creating a grid as a list of vectors

$
0
0

Hey, I want to create a grid on the n-dimensional sphere or cube so that all points of the grid are evenly distributed, similar to what [1:1:10] does in one dimension. Then I want to output the points as rows of a matrix, i.e. the j-th column of the matrix is the j-th point of the grid. I already tried the ndgrid command but the output is not really what I want.

submitted by /u/GlitterDeath666
[link] [comments]

Final thesis work

$
0
0

Hey guys! I have an array with 5479 days and I wanna just select the winter numbers.

time = (731217, 131218, ..., 736695)

Can I only select the 3 months of winter with a for bucle and add to a new array? I'm a little bit rusty with Matlab.

submitted by /u/josssep
[link] [comments]

State weighting matrix derived from Bryson's rule

$
0
0

I used Bryson's rule to derive the initial state weighting matrix for a 14 state system. I got a matrix with the weighting values for the first and eighth state that was more than 28 orders greater than the other ones. This is for a suspension system for a full car model. Is this normal? What can cause something like this if this is not normal? I put the initial state weighting matrix below.

[2.56686776972180e+30 0 0 0 0 0 0 0 0 0 0 0 0 0

0 9.74861530609360 0 0 0 0 0 0 0 0 0 0 0 0

0 0 3.29310057572890 0 0 0 0 0 0 0 0 0 0 0

0 0 0 1.68210062713359 0 0 0 0 0 0 0 0 0 0

0 0 0 0 1.68210062713359 0 0 0 0 0 0 0 0 0

0 0 0 0 0 1.81757181259173 0 0 0 0 0 0 0 0

0 0 0 0 0 0 1.81757181259173 0 0 0 0 0 0 0

0 0 0 0 0 0 0 2.60883367921748e+28 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0.0813331929426376 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0.0288482662710076 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0.0124688989259616 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0.0124688989259616 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0.0126460713309019 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0.0126460713309019];

submitted by /u/EOFFJM
[link] [comments]

Legends in MATLAB/Octave

what is your cpu, motherboard, memory, gpu spec?

How to define matrix-valued functions

$
0
0

I would like to define a function which looks at entries in a matrix as inputs, but I don't know how to tell matlab to not-assign values to a variable and instead just take whatever text file it's given with such data.

Like if I want to define categories based on a matrix, say column 1 is category 1, column 2 is category 2, column 3 is category 3, but I don't know how many entries the column well have, how do I define the function such that it may accommodate the user's arbitrary number of rows for each column?

submitted by /u/RedditRandoQuestions
[link] [comments]

Evaluating dsolve equations numerically

$
0
0

So I've solved a first oder differential equation using dsolve with a single initial condition. The output I got is correct, however I now need to evaluate this dsolve numerically, the constants within the expression have been predefined earlier in the code. The input variable in my equation is 't' and it comes from a matrix that was defined earlier in the code as well. I need to use dsolve to get credit for this problem however idk how to input the values needed into the output of the dsolve to evaluate the expressions for the parameters I need.

This is the result of my dsolve.

exp(-(Ar*H*t)/(C*m))*(Ta - TO) - Ta

submitted by /u/Bobby_Shmurda6969
[link] [comments]

Sending well-formatted email from MatLab

$
0
0

I know how to (barely) send email through MatLab, however when i send them, I cannot even figure out how to put in a Carriage Return, let alone changing Font, Font Size, etc. In case you were unaware that this existed, the command is

sendmail(recipients,subject,message,attachments)

however any attempt to format the message is a bust.

Any ideas?

submitted by /u/ShootHisRightProfile
[link] [comments]

Neural network predictive controller (NNPC) anyone ?

$
0
0

Hello.

Does anyone here have experience with NN predictive controller? I am an undergraduate student researcher and recently came across both MPC and NNPC. I Watched YouTube videos to understand what and how an MPC works. And for the NNPC there aren’t many videos. Based on my understanding I can apply NNPC in my research but I don’t have the sufficient knowledge when it comes to using it properly. So if anyone here has experience with NNPC plz let me know and I’ll discuss the problem in detail.

Thanks

submitted by /u/Francescodepazzi
[link] [comments]

Create Chart with Two Y-Axes

Matlab: xcorr: Having trouble when I try to calculate delay between two sinusoids

$
0
0

Hello everyone,

I have a problem when I try to use Matlab built-in function for cross-correlation 'xcorr'.

Background: I created two sinusoids, one of them delayed in time. I choose center frequencies of these signals slightly different than another. In this way, I am trying to analyze the effects of frequency mismatch on cross-correlation results. Problem: The problem is when I try to calculate delay using xcorr function in MatLab, I could not find the exact lag. The result is quite far away from my offset-time. I try to increase my signal length or sampling frequency. But nothing changes.

Do you have any idea? Here is my simple code, below.

clc clear all close all Fs=48e3; dt=1/Fs; t=0:dt:(4*Fs-1)*dt; CarrierFreq=5e3; Dev=50; CarrierFreqDev=CarrierFreq +Dev*(2*randi(2,1)-3); Offset=10000; OffsetTime=Offset*dt; NoisePower=-120; DesiredSNR=20; % Signal Power ReceivedSignalPower=NoisePower+DesiredSNR; ReceivedSignalPowerWatt=10^(ReceivedSignalPower/10); NoisePowerWatt=10^(NoisePower/10); % Generate Noise @ specified power Noise1 = wgn(1,length(t),NoisePowerWatt,'linear'); Noise2 = wgn(1, length(t),NoisePowerWatt,'linear'); % Generate Signal1 @ specified power Signal1=cos(2*pi*CarrierFreq*t); pSignal1 = sum(Signal1.^2) / length(Signal1); Signal1 = Signal1/sqrt(pSignal1); Signal1_Norm=sqrt(ReceivedSignalPowerWatt)*Signal1; Signal1=Signal1_Norm+Noise1; % Generate Delayed Signal @ specified power Signal2=cos(2*pi*CarrierFreqDev*t); pSignal2=sum(Signal2.^2) / length(Signal2); Signal2_Norm=sqrt(ReceivedSignalPowerWatt)*Signal2; Signal_Delay=circshift(Signal2_Norm, -Offset); Signal2=Signal_Delay+Noise2; [Coeff, Delay_Time] = xcorr(Signal1,Signal2); %% with dev. [ ~,Indx] = max(abs(Coeff)); Delay_Time = Delay_Time(Indx)*dt; 
submitted by /u/padmapatil_
[link] [comments]
Viewing all 31104 articles
Browse latest View live