How do I extract numbers from a matrix, use them in equations in the program and then assign all numbers in specific columns to variables.
조회 수: 54 (최근 30일)
이전 댓글 표시
I have a matrix that is about 18x26. I am attempting to extract specific numbers in the matrix and then assigning them to specific variables in order to solve an equation? Also, is it possible to extract a whole row from a matrix with the numbers automatically being assigned to specific variables? I think some of this will involve "if" statements and "for" loops based on the repetitive nature but I'm not sure.
댓글 수: 0
답변 (2개)
KALYAN ACHARJYA
2020년 5월 2일
편집: KALYAN ACHARJYA
2020년 5월 2일
mat_data(row,cloumns)
Use the conditional indexing, it great way to represents any matrix data. If you can share some specific example, it would be easy to explain.
Example
>> data=rand(18,26);
Lets exctract 2 row data, 2nd row with all columns
>> data(2,:)
ans =
Columns 1 through 12
0.9058 0.9595 0.3171 0.4984 0.2435 0.0540 0.7482 0.3998 0.0760 0.4039 0.2963 0.7948
Columns 13 through 24
0.1707 0.1174 0.2316 0.6538 0.5767 0.8175 0.3993 0.7379 0.5612 0.5830 0.3127 0.9686
Columns 25 through 26
0.9577 0.0012
More:
varivale_name=data(2,3)l ; Extract Single Element 2nd row & 3rd column
var_name=data(condition,:); Extract all rows, which satisfy the condition & all columns (":", represents all)
Also, is it possible to extract a whole row from a matrix with the numbers automatically being assigned to specific variables?
Yes, suggested to avoid the multiple variables names, consider array for scalars, or cell array for all others data types. Example: "whole single row data may be columns vector"
vec1=data(:,columns_num); columns_num or range of columns numbers like 1:5, 1 to 5
Any more clarifications, let me know with specific example
Good Wishes
댓글 수: 4
Walter Roberson
2021년 11월 27일
Array = [0 1 2 3 4 5];
syms alpha
solutions = arrayfun(@(U) solve(U*2 == U - 1*alpha*(U+2), alpha), Array)
Avenger2020
2020년 11월 5일
Instead of calling out a specific row. i want to call out a specific value from you matric. For example, calling out 0.2316 and giving it a variable zi. Then minus that value from the previous value in the same column (this will be zi-1)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!