Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:44:46+00:00 2026-05-27T20:44:46+00:00

I want a variable in matlab to store(not to be confused with display) only

  • 0

I want a variable in matlab to store(not to be confused with display) only upto 4 decimal places.
Is there an inbuilt command for it?
I tried the following – but this gives an error:

a = [5.21365458 5.236985475 1.236598547 9.3265874];

k=1;
for i=1:length(a)
ast(k)=sprintf('%5.4f',a(i));
anum(k)=str2num(ast(k));
k=k+1;
end

error is : ??? Subscripted assignment dimension mismatch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:44:47+00:00Added an answer on May 27, 2026 at 8:44 pm

    You should round the numbers to four decimal places. This is easy to do in the workspace:

    >> x = rand(1,4)
    x =
       0.053378064308120   0.051670599653141   0.924623792776560   0.585692341974519
    >> x = round(x*1e4) / 1e4
    x =
       0.053400000000000   0.051700000000000   0.924600000000000   0.585700000000000
    

    or you could write a function roundToDP(x,numberOfDecimalPlaces) that does it for you:

    function x = roundToDP(x,n)
    % "Round the matrix x to n decimal places"
    x = round(x * 10^n) / 10^n;
    

    now you can use that function in the workspace:

    >> x = rand(1,4)
    x =
       0.810201981892601   0.165116049955136   0.457688639337064   0.985975706057179
    >> roundToDP(x,4)
    ans =
       0.810200000000000   0.165100000000000   0.457700000000000   0.986000000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use the Matlab save command inside a function to store
Assume there's a myfile.csv with variable names in the first row and decimal numbers
I want the variable to take a default value when a value not passed
In my matlab program, I want to determine whether a variable or output of
so i have many controllers and many views. i want my variable @random_quote to
I have a long snippet of HTML I want some javascript variable to equal
I am developing one web application. In that i want to use variable's value
I want to pass a variable to a UIButton action, for example NSString *string=@one;
I want to add a variable number of records in a table (days) And
I want to pass a variable to he buttonEvent method in the selector. [button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.