現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Function not returning full matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Rafael
2017 年 12 月 8 日
I have a matrix around 20,000 by 20 and when I use this codes it only returns 1000 by 20. I'm sure the problem has to be on the for loop I just don't know how to get this function to show me the whole matrix.
function ....
i=length(data_2);
for i=1:data_2
fprintf...
.....
end
end
13 件のコメント
KSSV
2017 年 12 月 8 日
Don;t use length.......check with size. length gives you only maximum dimension......
Stephen23
2017 年 12 月 8 日
Never use length in your code, because its output is not very useful. Use size or numel as required, but never use length.
Jos (10584)
2017 年 12 月 8 日
These two lines are weird (and wrong)!
i=length(data_2);
for i=1:data_2_
I think you want something like
N = numel(data_2_)
for i=1:N
Rafael
2017 年 12 月 8 日
編集済み: Rafael
2017 年 12 月 8 日
numel fixed the problem. However, now I'm getting another problem since I changed
i=length(data_2) to N=numel(data_2)
The errors says, Index exceeds matrix dimensions.
Error in project (line6)
fprintf('%5.0f', data_2(i,1));
If I change the i to an N it says the same thing as if I leave it as an i.
James Tursa
2017 年 12 月 8 日
Please show the current entire code snippet that is causing the problem.
Rafael
2017 年 12 月 8 日
function [i]=table(data_2)
clc
fprintf('A B C D E F G H I J K L M N O P\n');
N=numel(data_2);
for i=N
fprintf('%1.0f',data_2(i,1));
fprintf('%1.0f',data_2(i,2));
fprintf('%1.0f',data_2(i,3));
fprintf('%1.0f',data_2(i,4));
fprintf('%1.0f',data_2(i,5));
fprintf('%1.0f',data_2(i,6));
fprintf('%1.0f',data_2(i,7));
fprintf('%1.0f',data_2(i,8));
fprintf('%1.0f',data_2(i,9));
fprintf('%1.0f',data_2(i,10));
fprintf('%1.0f',data_2(i,11));
fprintf('%1.0f',data_2(i,12));
fprintf('%1.0f',data_2(i,13));
fprintf('%1.0f',data_2(i,14));
fprintf('%1.0f',data_2(i,15));
fprintf('%1.0f',data_2(i,16));
fprintf('\n')
end
end
Rafael
2017 年 12 月 8 日
whos data_2 returns
Name Size Bytes Class Attributes
data_2 20,000x20 44k double
Rafael
2017 年 12 月 8 日
What do you mean in plain English. It's exactly what I said. I created a function that puts label on top of each columns. The problem is that it's not returning the whole matrix when I call it. It only returns 1000 by 20 matrix instead of the 20,000 by 20. So, when I use size(data_2,1) it only returns the last row of the matrix.
Rafael
2017 年 12 月 8 日
I know it sounds confusing. If you'd see it you would understand what I am trying to do.
To make it clear. I have an array or matrix that has 20,000 rows and 20 columns. When I call the matrix which is called data_2 it returns the whole matrix like this,
Column 1 through 13
.................
Column 14 through 20
.................
I created a function which organize the matrix and puts label on top of each columns like this,
A B C D E F G...
1 2 3 4 5 6 7...
1 2 3 4 5 6 7...
So, the problem is that when I created this function and I called it returns only 1000 rows and 20 columns. It is not returning the whole matrix which is what I want.
function ....
i=length(data_2);
for i=1:data_2
fprintf...
.....
end
end
If I use,
i=size(data_2,1)
n=1:i
It only returns the last row from the matrix.
Rafael
2017 年 12 月 8 日
If I run that it returns the whole matrix which is what I want. Now, it doesn't return the headers and it returns the matrix in the wrong order.
Rafael
2017 年 12 月 8 日
Yes, I understand you were just giving me an example. I did have something inside that, but it is not returning on top of the columns. I copy you exact code for fprintf.
The order is from 10 13 7 up to row 20,000 for rows and columns is from 1 to 20. These codes returned it as 39 3 41 etc.
Rafael
2017 年 12 月 9 日
The table is something like this, It goes from column 1 to 20 and row 1 to 20,000.
1 2 3 4 5 6 ... 20
10 13 17 43 76 42... 23
.
.
.
20,000
What I explained is that when I run the code you provided me, it returns those numbers in a different order like this,
1 2 3 4 5 6 ... 20
39 3 41 43 9 56... 1
.
.
.
18,390
採用された回答
Rafael
2017 年 12 月 10 日
Okay, now when I do which cssm is working. It tells me where it is saved.
5 件のコメント
Rafael
2017 年 12 月 10 日
The issue is when I tried to run your code,
colh = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'};
data = permute( reshape( (1:120), 20,6 ), [2,1] );
fprintf( 1, [repmat( '%4s, ' , 1,20 ),'\n'], colh{:});
fprintf( 1, [repmat( '%4.0f, ', 1,20 ),'\n'], data );
This returns a 6 rows and 20 columns matrix with the strings on top. So, when I tried to run this,
cssm(data,colh)
It returns, Error using cssm Too many input arguments.
Rafael
2017 年 12 月 10 日
function [colh]=cssm( data_2)
clc
colh = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'};
fprintf( [repmat( '%4s, ', 1,16 ),'\n'], colh{:} )
N = size( data_2, 1 );
for ii = 1 : N
fprintf([repmat('%4.0f, ',1,16),'\n'], data_2(ii,:))
end
end
Rafael
2017 年 12 月 10 日
Okay, I changed it. Now when I run cssm(data,colh) it returns the matrix from column 1 to 20 and row 1 to 101. Organized.
Rafael
2017 年 12 月 11 日
It returned the strings and the data which looks organized like in the original. However, it return it horizontally which doesn't fit in the command windows. It return and error.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)