how to identify rows and columns of a random array with a undetermind amont of rows or colloms

3 ビュー (過去 30 日間)
_______BEGINING OF CODE___________________
n=0
while n<5 || n>25
n=input('please enter a value 5<n<25---');
if n<5 || n>25
disp('the value isnt vaild,try again');
end
end
array=round(100*rand(n,n))
total_sum=0;
________END OF CODE________________
so basically if I wanted to find the sum of say row 2, how can I declare row 2 as B? so that row "n" can be the equivalent of its place in the alphabet.. example Row1=a Row2=b Row3=c exc... and column1=aa column2=bb exc..

採用された回答

Hikaru
Hikaru 2015 年 2 月 10 日
I'm just stating my opinion here. But, do you really need to name the rows and columns as specific variables? Isn't it more efficient to just use the index? For example, if you want the user to input which row they are interested in finding the sum of, then:
sum(array(k,:)) % where k is any number indicating the row

その他の回答 (1 件)

fred brunn
fred brunn 2015 年 2 月 10 日
編集済み: fred brunn 2015 年 2 月 10 日
___CODE_____
clc;
clear;
n=0
while n<5 n>25
n=input('please enter a value 5<n<25---');
if n<5 || n>25
disp('the value isnt vaild,try again');
end
end array=round(100*rand(n,n))
%find the sum to any row row_number=input('to find the sum of any row please enter a row number') ROW_SUM=sum(array(row_number,:)) fprintf('sum of row selected is---%f\n',ROW_SUM)
%find the collum to any row collum_number=input('to find the sum of any collum please enter a row number') COLLUM_SUM=sum(array(:,collum_number)) fprintf('sum of row selected is---%f\n',COLLUM_SUM)
___________END_______________
worked great thanks for the advice :)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by