random number selection code

조회 수: 6 (최근 30일)
Bilal Khurshid
Bilal Khurshid 2019년 8월 2일
댓글: Bilal Khurshid 2019년 8월 2일
i have matrix (11x5), i want to generate random number for each matrix value in the range (1-A/9)
where A=entries of matrix, the output file should also be of size 11x5 (with every number selected in the range 1-A/9)
i am writing code but facing problem,plz help
program
  • clear all
  • clc
  • A = (textread('data_mat_car01_11x5.txt'))'
  • B=A/9
  • range=[min(1) max(B)
  • E=randperm(length(B),10)
  • fprintf
  댓글 수: 2
Jon
Jon 2019년 8월 2일
편집: Jon 2019년 8월 2일
You say you are facing a problem, but please be more specific about what the problem is. Are you getting MATLAB errors that you don't understand. If so please, include your actual code rather than a bulleted list by copy and pasting and using the "insert line of code" button in the MATLAB answers toolbar. Also please copy and paste the full error message that you are getting.
If instead you need assistance with framing your problem and how to use MATLAB to implement your solution than you will need to please explain the goal of what you are trying to accomplish more clearly.
It is not clear what you mean by "generate random number for each matrix value in the range (1-A/9)" Here are just a few points of confusion. First in the expression (1-A/9) is that - indicating subtraction or do you mean a number between 1 and A/9?. Second, A is an 11 row by 5 column matrix so when you say in the range (1 -A/9) the second term A/9 has different values for every entry in A, do you mean that if we call the 11 by 5 output matrix R, then R(i,j) must be be between 1 and A(i,j)/9?
Bilal Khurshid
Bilal Khurshid 2019년 8월 2일
Thanks for your response
i am unable to write complete code.
A is a matrxi of size 11x5,i will explain in steps what i need
  1. Pick all values of matrix A.
  2. Divide all values of matrix A by 9 and save it as matrix B.
  3. Make another matrix C and each field (Cij) of matrix C be such that its value is in between 1 and B (forexample first value (C11) of matrix A is 375, and 375/9=41.66 , so value for this field C11 should be randomly selected between 1 to 41).
  4. Repeat this procedure for all the fields of matrix.
I have added sample result file for more info, please check it and let me know if you need some information.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by