Question

In: Computer Science

I'm new in MATLAB and I have to write a code in MATLAB which converts a...

I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc

Solutions

Expert Solution

So i am taking an example.

we will Write code to convert a number from any base to decimal. The input (number to be converted) is represented as a vector of size n where n represents number of digits.

  • First ask the user to enter the number in vector form
  • and then ask for base of number
  • Iterate over the vector backwards
  • apply the formula for conversion
  • print the final decimal number

MATLAB CODE-

%ask for input number as vector
v = input('Enter the number to be converted as vector : ');
%ask for its based
b = input('Enter the base of the input number : ' );
n = length(v); %store the length of vector
c = 0; %to store the counter for power of base
d = 0; %to store the final decimal converted number
%iterate over the vector input number backwards
for i = n:-1:1
%use the formula for conversion
d = d + ((b^c)*v(i));
%increment the power to base by 1
c = c + 1;
end
%print the final decimal number
fprintf('Final decimal converted number : %d\n',d);

IMAGE OF CODE-

OUTPUT-

Case 1

Case 2

****PLEASE DON'T FORGET TO GIVE THUMBS UP. I REALLY NEED IT


Related Solutions

Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
The source code I have is what i'm trying to fix for the assignment at the...
The source code I have is what i'm trying to fix for the assignment at the bottom. Source Code: #include <iostream> #include <cstdlib> #include <ctime> #include <iomanip> using namespace std; const int NUM_ROWS = 10; const int NUM_COLS = 10; // Setting values in a 10 by 10 array of random integers (1 - 100) // Pre: twoDArray has been declared with row and column size of NUM_COLS // Must have constant integer NUM_COLS declared // rowSize must be less...
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
I'm very confused on how to complete this code. There are 5 total classes. I have...
I'm very confused on how to complete this code. There are 5 total classes. I have some written but it isn't quite working and the Band class especially is confusing me. I posted the entire thing since the band and manager class refer to the other classes' constructors and thought it would be helpful to post those as well. Person class is a base class: Private variables String firstname, String lastname, int age Constructor has the parameters String firstname, String...
Write a new MATLAB function as described in the following: 1. The new function will have...
Write a new MATLAB function as described in the following: 1. The new function will have three input parameters: f, W, C. 2. Parameter f will specify the frequency of the square wave. 3. The parameter W will specify the width of the single pulse as a number of sample periods. 4. The parameter C will specify the number of square wave cycles. 5. Calculate a number of samples, N, to run the simulation for both waveforms. 6. Create one...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im...
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im not too familar with how all the plotting and drawing functions work.
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT